积极答复者
protected override void OnPaint(PaintEventArgs e)

问题
答案
-
标题的那句话不是属性也不是事件,只是一个方法,是一个画图方法,控件要显示出来就是通过这个方法把控件或窗体画出来呈现给用户看的,标题那句话只能通过人工去输入,那句是用来重写控件的显示才使用的,比如你想自定义一个按钮控件,使它显示的背景是红色,此时你可以重写Button按钮,此时就需要使用到OnPaint这个方法了,具体代码如下:
// 这样就创建了一个自定义控件了,当你编译完切换到窗体的工具箱中会多出你自定义的控件,当你把你自定义的控件拖到窗体时,发现它背景色为红色,与传统的Button按钮有所不同 public class mybutton:System.Windows.Forms.Button { protected override void OnPaint(PaintEventArgs e) { // Call the OnPaint method of the base class. base.OnPaint(e); Text = ""; BackColor = Color.Red; } }
If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample
- 已标记为答案 杲大盛 2013年6月1日 11:55
全部回复
-
标题的那句话不是属性也不是事件,只是一个方法,是一个画图方法,控件要显示出来就是通过这个方法把控件或窗体画出来呈现给用户看的,标题那句话只能通过人工去输入,那句是用来重写控件的显示才使用的,比如你想自定义一个按钮控件,使它显示的背景是红色,此时你可以重写Button按钮,此时就需要使用到OnPaint这个方法了,具体代码如下:
// 这样就创建了一个自定义控件了,当你编译完切换到窗体的工具箱中会多出你自定义的控件,当你把你自定义的控件拖到窗体时,发现它背景色为红色,与传统的Button按钮有所不同 public class mybutton:System.Windows.Forms.Button { protected override void OnPaint(PaintEventArgs e) { // Call the OnPaint method of the base class. base.OnPaint(e); Text = ""; BackColor = Color.Red; } }
If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample
- 已标记为答案 杲大盛 2013年6月1日 11:55