如下代码会执行OnPaint方法:
- public class Class1 : TextBox
- {
- protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
- {
- base.OnPaint(e);
- Console.WriteLine("TextBox OnPaint");
- }
- protected override void OnCreateControl()
- {
- base.OnCreateControl();
- this.SetStyle(ControlStyles.UserPaint, true);
- Refresh();
- }
- }
复制代码
如果继承C1TextBox就不会执行OnPaint,这个问题该如何实现
- public class Class2 : C1TextBox
- {
- protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
- {
- base.OnPaint(e);
- Console.WriteLine("C1TextBox OnPaint");
- }
- protected override void OnCreateControl()
- {
- base.OnCreateControl();
- this.SetStyle(ControlStyles.UserPaint, true);
- Refresh();
- }
- }
复制代码 |
|