* UITabControl:增加只显示激活窗体关闭按钮

This commit is contained in:
Sunny 2020-06-27 20:09:19 +08:00
parent af63124c44
commit 18072dfc1a
10 changed files with 102 additions and 18 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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);
}
}
}

View File

@ -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; }

View File

@ -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;
}
}
}

View File

@ -2,6 +2,7 @@
2020.06.27
* UITabControl重绘左右按钮
+ UITabControl增加只显示激活窗体关闭按钮
2020.06.26
+ UIDoughnutChart增加控件环状图