public partial class MyTableLayoutPanel :TableLayoutPanel
{
[Description("边框颜色"), Category("BorderColor"), DefaultValue(typeof(Color), "Black")]
private Color borderColor = Color.Black;
public Color BorderColor
{
get { return borderColor; }
set
{
this.borderColor = value;
this.Invalidate();
}
} public MyTableLayoutPanel()
{
InitializeComponent();
}
protected override void OnCellPaint(TableLayoutCellPaintEventArgs e)
{
base.OnCellPaint(e);
Graphics g = e.Graphics; Pen myPen = new Pen(borderColor);
g.DrawRectangle(myPen,
e.CellBounds.Location.X + 1,
e.CellBounds.Location.Y + 1,
e.CellBounds.Width,
e.CellBounds.Height); }
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawRectangle(new Pen(borderColor), e.ClipRectangle.Location.X, e.ClipRectangle.Location.Y, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 1);
}
}
将这个自定义控件添加到工具箱里面,然后在拖放到窗体上时,提示:索引超出范围,必须为非负值必须小于集合大小,参数名:index
额,没分了
把其它窗口(例如QQ聊天对话框)拖放到带有此控件的窗口上时,会出现前置窗口边框的线(QQ聊天对话框)放其他窗口也一样。。Why...