tab control 重绘关闭按钮
我想在tab control 的选页卡上增加一个关闭按钮,据说是要重绘,谁知道怎么做啊!不胜感激。
以下是网上找的C#的,C++的怎么写呢?
namespace Yoramo.GuiLib
{
public delegate bool PreRemoveTab(int indx);
public class TabControlEx : TabControl
{
public TabControlEx()
: base()
{
PreRemoveTabPage = null;
this.DrawMode = TabDrawMode.OwnerDrawFixed;
}
public PreRemoveTab PreRemoveTabPage;
protected override void OnDrawItem(DrawItemEventArgs e)
{
Rectangle r = e.Bounds;
r = GetTabRect(e.Index);
r.Offset(2, 2);
r.Width = 5;
r.Height = 5;
Brush b = new SolidBrush(Color.Black);
Pen p = new Pen(b);
e.Graphics.DrawLine(p, r.X, r.Y, r.X + r.Width, r.Y + r.Height);
e.Graphics.DrawLine(p, r.X + r.Width, r.Y, r.X, r.Y + r.Height);
string titel = this.TabPages[e.Index].Text;
Font f = this.Font;
e.Graphics.DrawString(titel, f, b, new PointF(r.X + 5, r.Y));
}
protected override void OnMouseClick(MouseEventArgs e)
{
Point p = e.Location;
for (int i = 0; i < TabCount; i++)
{
Rectangle r = GetTabRect(i);
r.Offset(2, 2);
r.Width = 5;
r.Height = 5;
if (r.Contains(p))
{
CloseTab(i);
}
}
}
private void CloseTab(int i)
{
if (PreRemoveTabPage != null)
{
bool closeIt = PreRemoveTabPage(i);
if (!closeIt)
return;
}
TabPages.Remove(TabPages[i]);
}
}
}
[解决办法]
tab control VC的使用要自己控制每一个控件,最好做成函数处理