Commit 5fded8fc HZH

add tabControl closeBtn

1 个父辈 2666394f
......@@ -21,6 +21,10 @@ namespace HZH_Controls.Controls
this.ItemSize = new Size(this.ItemSize.Width, 50);
}
private void SetStyles()
{
base.SetStyle(
......@@ -32,6 +36,8 @@ namespace HZH_Controls.Controls
ControlStyles.SupportsTransparentBackColor, true);
base.UpdateStyles();
}
[Description("是否显示关闭按钮"), Category("自定义")]
public bool IsShowCloseBtn { get; set; }
private Color _backColor = Color.White;
[Browsable(true)]
......@@ -172,6 +178,12 @@ namespace HZH_Controls.Controls
this.PaintTabBorder(e.Graphics, index, path);
this.PaintTabText(e.Graphics, index);
this.PaintTabImage(e.Graphics, index);
if (IsShowCloseBtn)
{
Rectangle rect = this.GetTabRect(index);
e.Graphics.DrawLine(new Pen(_borderColor, 1F), new Point(rect.Right - 15, rect.Top + 5), new Point(rect.Right - 5, rect.Top + 15));
e.Graphics.DrawLine(new Pen(_borderColor, 1F), new Point(rect.Right - 5, rect.Top + 5), new Point(rect.Right - 15, rect.Top + 15));
}
}
/// <summary>
......@@ -346,5 +358,50 @@ namespace HZH_Controls.Controls
SendMessage(this.Handle, WM_FONTCHANGE, IntPtr.Zero, IntPtr.Zero);
this.UpdateStyles();
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0201) // WM_LBUTTONDOWN
{
if (!DesignMode)
{
if (IsShowCloseBtn)
{
var mouseLocation = this.PointToClient(Control.MousePosition);
int index = GetMouseDownTabHead(mouseLocation);
if (index >= 0)
{
Rectangle rect = this.GetTabRect(index);
var closeRect = new Rectangle(rect.Right - 15, rect.Top + 5, 10, 10);
if (closeRect.Contains(mouseLocation))
{
this.TabPages.RemoveAt(index);
return;
}
}
}
}
}
base.WndProc(ref m);
}
public override bool PreProcessMessage(ref Message msg)
{
return base.PreProcessMessage(ref msg);
}
private int GetMouseDownTabHead(Point point)
{
for (int i = 0; i < this.TabCount; i++)
{
Rectangle rect = this.GetTabRect(i);
if (rect.Contains(point))
{
return i;
}
}
return -1;
}
}
}
......@@ -59,6 +59,7 @@
this.tabControlExt1.Controls.Add(this.tabPage5);
this.tabControlExt1.Controls.Add(this.tabPage6);
this.tabControlExt1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControlExt1.IsShowCloseBtn = true;
this.tabControlExt1.ItemSize = new System.Drawing.Size(142, 50);
this.tabControlExt1.Location = new System.Drawing.Point(0, 0);
this.tabControlExt1.Multiline = true;
......@@ -67,6 +68,7 @@
this.tabControlExt1.Size = new System.Drawing.Size(528, 321);
this.tabControlExt1.SizeMode = System.Windows.Forms.TabSizeMode.FillToRight;
this.tabControlExt1.TabIndex = 0;
this.tabControlExt1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tabControlExt1_KeyDown);
//
// tabPage7
//
......
......@@ -15,5 +15,10 @@ namespace Test
{
InitializeComponent();
}
private void tabControlExt1_KeyDown(object sender, KeyEventArgs e)
{
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!