* UITabControl: 关闭按钮增加鼠标移入的效果

This commit is contained in:
Sunny 2022-04-18 21:54:48 +08:00
parent c495c5c425
commit ce8c3f8f89
2 changed files with 41 additions and 6 deletions

View File

@ -66,6 +66,7 @@ namespace Sunny.UI.Demo
this.uiTabControlMenu1.Size = new System.Drawing.Size(670, 239);
this.uiTabControlMenu1.SizeMode = System.Windows.Forms.TabSizeMode.Fixed;
this.uiTabControlMenu1.TabIndex = 25;
this.uiTabControlMenu1.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0);
//
// tabPage5
//
@ -106,7 +107,6 @@ namespace Sunny.UI.Demo
// uiLine2
//
this.uiLine2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLine2.IsScaled = false;
this.uiLine2.Location = new System.Drawing.Point(30, 286);
this.uiLine2.MinimumSize = new System.Drawing.Size(16, 16);
this.uiLine2.Name = "uiLine2";
@ -114,11 +114,11 @@ namespace Sunny.UI.Demo
this.uiLine2.TabIndex = 24;
this.uiLine2.Text = "UITabControlMenu";
this.uiLine2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.uiLine2.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0);
//
// uiLine1
//
this.uiLine1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLine1.IsScaled = false;
this.uiLine1.Location = new System.Drawing.Point(30, 55);
this.uiLine1.MinimumSize = new System.Drawing.Size(16, 16);
this.uiLine1.Name = "uiLine1";
@ -126,6 +126,7 @@ namespace Sunny.UI.Demo
this.uiLine1.TabIndex = 23;
this.uiLine1.Text = "UITabControl";
this.uiLine1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.uiLine1.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0);
//
// uiTabControl1
//
@ -145,11 +146,12 @@ namespace Sunny.UI.Demo
this.uiTabControl1.MenuStyle = Sunny.UI.UIMenuStyle.Custom;
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 = 22;
this.uiTabControl1.TipsFont = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiTabControl1.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0);
this.uiTabControl1.BeforeRemoveTabPage += new Sunny.UI.UITabControl.OnBeforeRemoveTabPage(this.uiTabControl1_BeforeRemoveTabPage);
//
// tabPage1
@ -175,7 +177,7 @@ namespace Sunny.UI.Demo
this.tabPage3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
this.tabPage3.Location = new System.Drawing.Point(0, 40);
this.tabPage3.Name = "tabPage3";
this.tabPage3.Size = new System.Drawing.Size(200, 60);
this.tabPage3.Size = new System.Drawing.Size(670, 143);
this.tabPage3.TabIndex = 2;
this.tabPage3.Text = "tabPage3";
//
@ -183,7 +185,7 @@ namespace Sunny.UI.Demo
//
this.tabPage9.Location = new System.Drawing.Point(0, 40);
this.tabPage9.Name = "tabPage9";
this.tabPage9.Size = new System.Drawing.Size(200, 60);
this.tabPage9.Size = new System.Drawing.Size(670, 143);
this.tabPage9.TabIndex = 4;
this.tabPage9.Text = "tabPage9";
this.tabPage9.UseVisualStyleBackColor = true;

View File

@ -25,6 +25,7 @@
* 2021-08-14: V3.0.6 DisposeTabPageAfterRemove标志TabPage后TabPage
* 2022-01-02: V3.0.9
* 2022-01-13: V3.1.0
* 2022-04-18: V3.1.5
******************************************************************************/
using Sunny.UI.Win32;
@ -574,6 +575,8 @@ namespace Sunny.UI
}
}
private ConcurrentDictionary<int, bool> CloseRects = new ConcurrentDictionary<int, bool>();
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
@ -633,7 +636,13 @@ namespace Sunny.UI
{
if (ShowCloseButton || (ShowActiveCloseButton && index == SelectedIndex))
{
g.DrawFontImage(77, 28, index == SelectedIndex ? tabSelectedForeColor : TabUnSelectedForeColor, new Rectangle(TabRect.Width - 28, 0, 24, TabRect.Height));
Color color = TabUnSelectedForeColor;
if (CloseRects.ContainsKey(index) && CloseRects[index])
{
color = tabSelectedForeColor;
}
g.DrawFontImage(77, 28, color, new Rectangle(TabRect.Width - 28, 0, 24, TabRect.Height));
}
}
@ -671,6 +680,29 @@ namespace Sunny.UI
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (ShowActiveCloseButton || ShowCloseButton)
{
for (int index = 0; index <= TabCount - 1; index++)
{
Rectangle TabRect = new Rectangle(GetTabRect(index).Location.X - 2, GetTabRect(index).Location.Y - 2, ItemSize.Width, ItemSize.Height);
Rectangle closeRect = new Rectangle(TabRect.Right - 28, 0, 28, TabRect.Height);
bool inrect = e.Location.InRect(closeRect);
if (!CloseRects.ContainsKey(index))
CloseRects.TryAdd(index, false);
if (inrect != CloseRects[index])
{
CloseRects[index] = inrect;
Invalidate();
}
}
}
}
Font tmpFont;
private Font TempFont
@ -819,6 +851,7 @@ namespace Sunny.UI
protected override void OnSelectedIndexChanged(EventArgs e)
{
base.OnSelectedIndexChanged(e);
CloseRects.Clear();
Init();
if (ShowActiveCloseButton && !ShowCloseButton)
{