diff --git a/Bin/SunnyUI.dll b/Bin/SunnyUI.dll index 3dc3dcb8..080430c9 100644 Binary files a/Bin/SunnyUI.dll and b/Bin/SunnyUI.dll differ diff --git a/Bin/SunnyUI.pdb b/Bin/SunnyUI.pdb index 0ff5787f..77777225 100644 Binary files a/Bin/SunnyUI.pdb and b/Bin/SunnyUI.pdb differ diff --git a/SunnyUI.Demo/Bin/SunnyUI.Demo.exe b/SunnyUI.Demo/Bin/SunnyUI.Demo.exe index 0f164f3b..ce937319 100644 Binary files a/SunnyUI.Demo/Bin/SunnyUI.Demo.exe and b/SunnyUI.Demo/Bin/SunnyUI.Demo.exe differ diff --git a/SunnyUI.Demo/Bin/SunnyUI.dll b/SunnyUI.Demo/Bin/SunnyUI.dll index 3dc3dcb8..080430c9 100644 Binary files a/SunnyUI.Demo/Bin/SunnyUI.dll and b/SunnyUI.Demo/Bin/SunnyUI.dll differ diff --git a/SunnyUI.Demo/Controls/FButton.Designer.cs b/SunnyUI.Demo/Controls/FButton.Designer.cs index cf9280f4..249e4bf2 100644 --- a/SunnyUI.Demo/Controls/FButton.Designer.cs +++ b/SunnyUI.Demo/Controls/FButton.Designer.cs @@ -984,6 +984,7 @@ // // FButton // + this.AlwaysOpen = true; this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 534); diff --git a/SunnyUI.Demo/Controls/FTabControl.Designer.cs b/SunnyUI.Demo/Controls/FTabControl.Designer.cs index df3d6a53..d4d617cf 100644 --- a/SunnyUI.Demo/Controls/FTabControl.Designer.cs +++ b/SunnyUI.Demo/Controls/FTabControl.Designer.cs @@ -35,6 +35,8 @@ this.tabPage9 = new System.Windows.Forms.TabPage(); this.tabPage10 = new System.Windows.Forms.TabPage(); this.tabPage11 = new System.Windows.Forms.TabPage(); + this.tabPage12 = new System.Windows.Forms.TabPage(); + this.tabPage13 = new System.Windows.Forms.TabPage(); this.tabPage4 = new System.Windows.Forms.TabPage(); this.uiLine1 = new Sunny.UI.UILine(); this.uiLine2 = new Sunny.UI.UILine(); @@ -64,6 +66,8 @@ this.uiTabControl1.Controls.Add(this.tabPage9); this.uiTabControl1.Controls.Add(this.tabPage10); this.uiTabControl1.Controls.Add(this.tabPage11); + this.uiTabControl1.Controls.Add(this.tabPage12); + this.uiTabControl1.Controls.Add(this.tabPage13); this.uiTabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed; this.uiTabControl1.Font = new System.Drawing.Font("微软雅黑", 12F); this.uiTabControl1.ItemSize = new System.Drawing.Size(150, 40); @@ -72,7 +76,6 @@ this.uiTabControl1.Name = "uiTabControl1"; this.uiTabControl1.SelectedIndex = 0; this.uiTabControl1.ShowActiveCloseButton = true; - this.uiTabControl1.ShowCloseButton = true; this.uiTabControl1.Size = new System.Drawing.Size(670, 183); this.uiTabControl1.SizeMode = System.Windows.Forms.TabSizeMode.Fixed; this.uiTabControl1.TabIndex = 0; @@ -132,6 +135,24 @@ this.tabPage11.Text = "tabPage11"; this.tabPage11.UseVisualStyleBackColor = true; // + // tabPage12 + // + this.tabPage12.Location = new System.Drawing.Point(0, 40); + this.tabPage12.Name = "tabPage12"; + this.tabPage12.Size = new System.Drawing.Size(670, 143); + this.tabPage12.TabIndex = 7; + this.tabPage12.Text = "tabPage12"; + this.tabPage12.UseVisualStyleBackColor = true; + // + // tabPage13 + // + this.tabPage13.Location = new System.Drawing.Point(0, 40); + this.tabPage13.Name = "tabPage13"; + this.tabPage13.Size = new System.Drawing.Size(670, 143); + this.tabPage13.TabIndex = 8; + this.tabPage13.Text = "tabPage13"; + this.tabPage13.UseVisualStyleBackColor = true; + // // tabPage4 // this.tabPage4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); @@ -250,5 +271,7 @@ private System.Windows.Forms.TabPage tabPage9; private System.Windows.Forms.TabPage tabPage10; private System.Windows.Forms.TabPage tabPage11; + private System.Windows.Forms.TabPage tabPage12; + private System.Windows.Forms.TabPage tabPage13; } } \ No newline at end of file diff --git a/SunnyUI/Controls/UINavMenuHelper.cs b/SunnyUI/Controls/UINavMenuHelper.cs index 3c7e473b..fa2fd132 100644 --- a/SunnyUI/Controls/UINavMenuHelper.cs +++ b/SunnyUI/Controls/UINavMenuHelper.cs @@ -285,8 +285,9 @@ namespace Sunny.UI if (pageIndex < 0) return; foreach (var item in PageItems) { - if (item.Value.PageIndex == pageIndex) + if (item.Value.PageIndex == pageIndex && item.Key!=null) { + if (tabControl.TabPages.Contains(item.Key)) tabControl.SelectTab(item.Key); } } @@ -297,9 +298,10 @@ namespace Sunny.UI if (guid == Guid.Empty) return; foreach (var item in PageItems) { - if (item.Value.PageGuid == guid) + if (item.Value.PageGuid == guid && item.Key != null) { - tabControl.SelectTab(item.Key); + if (tabControl.TabPages.Contains(item.Key)) + tabControl.SelectTab(item.Key); } } } diff --git a/SunnyUI/Controls/UITabControl.cs b/SunnyUI/Controls/UITabControl.cs index e9f9d206..1510194d 100644 --- a/SunnyUI/Controls/UITabControl.cs +++ b/SunnyUI/Controls/UITabControl.cs @@ -33,6 +33,8 @@ namespace Sunny.UI public sealed class UITabControl : TabControl, IStyleInterface { private readonly UITabControlHelper Helper; + private int DrawedIndex = -1; + private readonly Timer timer = new Timer(); public UITabControl() { @@ -46,6 +48,24 @@ namespace Sunny.UI Version = UIGlobal.Version; Helper = new UITabControlHelper(this); + timer.Interval = 500; + timer.Tick += Timer_Tick; + } + + private void Timer_Tick(object sender, EventArgs e) + { + timer.Stop(); + DrawedIndex = SelectedIndex; + } + + protected override void OnSelected(TabControlEventArgs e) + { + base.OnSelected(e); + + if (ShowActiveCloseButton && !ShowCloseButton) + { + timer.Start(); + } } protected override bool ProcessCmdKey(ref Message msg, Keys keyData) @@ -70,17 +90,17 @@ namespace Sunny.UI public void SelectPage(int pageIndex) => Helper.SelectPage(pageIndex); public void SelectPage(Guid pageGuid) => Helper.SelectPage(pageGuid); - + public void AddPage(UIPage page) => Helper.AddPage(page); - + public void AddPage(int pageIndex, UITabControl page) => Helper.AddPage(pageIndex, page); - + public void AddPage(int pageIndex, UITabControlMenu page) => Helper.AddPage(pageIndex, page); public void AddPage(Guid guid, UITabControl page) => Helper.AddPage(guid, page); - + public void AddPage(Guid guid, UITabControlMenu page) => Helper.AddPage(guid, page); - + public string Version { get; } private Color _fillColor = UIColor.LightBlue; @@ -320,27 +340,28 @@ namespace Sunny.UI private bool showCloseButton; - [DefaultValue(false)] + [DefaultValue(false),Description("所有Tab页面标题显示关闭按钮")] public bool ShowCloseButton { get => showCloseButton; set { showCloseButton = value; + if (showActiveCloseButton) showActiveCloseButton = false; Invalidate(); } } private bool showActiveCloseButton; - [DefaultValue(false)] - [Browsable(false)] + [DefaultValue(false), Description("当前激活的Tab页面标题显示关闭按钮")] public bool ShowActiveCloseButton { get => showActiveCloseButton; set { showActiveCloseButton = value; + if (showCloseButton) showCloseButton = false; Invalidate(); } } @@ -413,9 +434,10 @@ namespace Sunny.UI } } - protected override void OnMouseClick(MouseEventArgs e) + protected override void OnMouseDown(MouseEventArgs e) { - base.OnMouseClick(e); + base.OnMouseDown(e); + int removeIndex = -1; for (int index = 0; index <= TabCount - 1; index++) { @@ -433,11 +455,27 @@ namespace Sunny.UI return; } - if (ShowCloseButton || (ShowActiveCloseButton && removeIndex == SelectedIndex)) + removeIndex.ConsoleWriteLine("removeIndex"); + var menuItem = Helper[removeIndex]; + bool showButton = menuItem == null || !menuItem.AlwaysOpen; + if (showButton) { - if (BeforeRemoveTabPage == null || (BeforeRemoveTabPage != null && BeforeRemoveTabPage.Invoke(this, removeIndex))) + if (ShowCloseButton) { - RemoveTabPage(removeIndex); + if (BeforeRemoveTabPage == null || (BeforeRemoveTabPage != null && BeforeRemoveTabPage.Invoke(this, removeIndex))) + { + RemoveTabPage(removeIndex); + } + } + else if (ShowActiveCloseButton && removeIndex == SelectedIndex) + { + if (DrawedIndex == removeIndex) + { + if (BeforeRemoveTabPage == null || (BeforeRemoveTabPage != null && BeforeRemoveTabPage.Invoke(this, removeIndex))) + { + RemoveTabPage(removeIndex); + } + } } } } @@ -844,7 +882,7 @@ namespace Sunny.UI } public bool MouseOver { get; } - + public bool MousePress { get; } public bool MouseInUpButton { get; } diff --git a/SunnyUI/Frames/UIMainFrame.cs b/SunnyUI/Frames/UIMainFrame.cs index a15df320..bb7b64de 100644 --- a/SunnyUI/Frames/UIMainFrame.cs +++ b/SunnyUI/Frames/UIMainFrame.cs @@ -20,6 +20,7 @@ ******************************************************************************/ using System; +using System.ComponentModel; namespace Sunny.UI { @@ -64,5 +65,23 @@ namespace Sunny.UI } protected UITabControl MainTabControl => MainContainer; + + public bool TabVisible + { + get => MainContainer.TabVisible; + set => MainContainer.TabVisible = value; + } + + public bool TabShowCloseButton + { + get => MainContainer.ShowCloseButton; + set => MainContainer.ShowCloseButton = value; + } + + public bool TabShowActiveCloseButton + { + get => MainContainer.ShowActiveCloseButton; + set => MainContainer.ShowActiveCloseButton = value; + } } } \ No newline at end of file diff --git a/Updates.txt b/Updates.txt index 3d6485d6..bfe871f7 100644 --- a/Updates.txt +++ b/Updates.txt @@ -2,6 +2,7 @@ 2020.06.27 * UITabControlػҰť ++ UITabControlֻʾرհť 2020.06.26 + UIDoughnutChartӿؼ״ͼ