自定义panel控件
VS2008 winform中panel控件不能更改边框线条颜色,想自己做一个可以定义边框线条颜色的,以下是我代码,但报错,求指导.
public partial class TdPanel : UserControl
{
[DefaultValue(typeof(Color))]
public Color LineColor
{
get { return LineColor; }
set { LineColor = value; }
}
public TdPanel()
{
InitializeComponent();
}
private void TdPanel_Resize(object sender, EventArgs e)
{
panel1.Size = this.Size;
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics,
this.panel1.ClientRectangle,
this.LineColor, //left
1,
ButtonBorderStyle.Solid,
this.LineColor, //top
1,
ButtonBorderStyle.Solid,
this.LineColor, //right
1,
ButtonBorderStyle.Solid,
this.LineColor, //bottom
1,
ButtonBorderStyle.Solid);
}
}
public partial class TdPanel : UserControl
{
private Color lineColor = Color.Red;
[DefaultValue(typeof(Color))]
public Color LineColor
{
get { return lineColor; }
set { lineColor = value; this.Invalidate(); }
}
public TdPanel()
{
InitializeComponent();
}
private void TdPanel_Paint(object sender, PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics,
ClientRectangle,
this.LineColor, //left
1,
ButtonBorderStyle.Solid,
this.LineColor, //top
1,
ButtonBorderStyle.Solid,
this.LineColor, //right
1,
ButtonBorderStyle.Solid,
this.LineColor, //bottom
1,
ButtonBorderStyle.Solid);
}
}