怎样继承自带控件来实现自定义控件,都是需要继承哪些东西,比如一个button或者comobox,我知道根据需求不同,要继承的东西也不同,请大侠们说一个比较全面的吧,可以只简单的说方法就行。注意的问题,哪些是必须要继承的。
public Class MyButton : System.Windows.Forms.Button
{
//构造方法
........
//要继承的方法
........
}
...全文
955打赏收藏
怎样继承自带控件来实现自定义控件
怎样继承自带控件来实现自定义控件,都是需要继承哪些东西,比如一个button或者comobox,我知道根据需求不同,要继承的东西也不同,请大侠们说一个比较全面的吧,可以只简单的说方法就行。注意的问题,哪些是必须要继承的。 public Class MyButton : System.Windows.Forms.Button { //构造方法 ........ //要继承的方法 ........ }
下面是我写的一个继承textbox的一个自定义控件,希望对LZ有用~~LZ可以看看
public partial class Formtextbox : TextBox
{
public Formtextbox()
{
InitializeComponent();
}
private Color _linecolor = Color.Blue;
/// <summary>
/// 线条颜色
/// </summary>
public Color LineColor
{
get
{
return this._linecolor;
}
set
{
this._linecolor = value;
}
}
private const int WM_PAINT = 0xF;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
DrawLine();
}
private void DrawLine()
{
Graphics g = this.CreateGraphics();
using (Pen p = new Pen(this._linecolor,3))
{
Rectangle re = new Rectangle(0, 0, Width-1, Height-1);
g.DrawRectangle(p, re);