找回密码
 立即注册

QQ登录

只需一步,快速开始

tysoft

中级会员

84

主题

214

帖子

678

积分

中级会员

积分
678

活字格认证微信认证勋章元老葡萄

[已处理] C1TextBox OnPaint

tysoft
中级会员   /  发表于:2015-11-11 10:58  /   查看:3519  /  回复:1
如下代码会执行OnPaint方法:
  1. public class Class1 : TextBox
  2.     {

  3.         protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  4.         {
  5.             base.OnPaint(e);
  6.             Console.WriteLine("TextBox OnPaint");
  7.         }

  8.         protected override void OnCreateControl()
  9.         {
  10.             base.OnCreateControl();
  11.             this.SetStyle(ControlStyles.UserPaint, true);
  12.             Refresh();
  13.         }
  14.     }
复制代码

如果继承C1TextBox就不会执行OnPaint,这个问题该如何实现
  1. public class Class2 : C1TextBox
  2.     {
  3.         protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  4.         {
  5.             base.OnPaint(e);
  6.             Console.WriteLine("C1TextBox OnPaint");
  7.         }

  8.         protected override void OnCreateControl()
  9.         {
  10.             base.OnCreateControl();
  11.             this.SetStyle(ControlStyles.UserPaint, true);
  12.             Refresh();
  13.         }
  14.     }
复制代码

1 个回复

倒序浏览
Alice
社区贡献组   /  发表于:2015-11-11 12:27:00
沙发
回复 1楼tysoft的帖子

感谢您的反馈。
Paint事件(继承自System.Windows.Forms.Control)在C1TextBox里是被隐藏的,因为它包括TextBox,都是基于Win32的EDIT控件,他们的前景文字和背景色都是由Windows绘制,而不是我们的代码或是.NET Framework绘制。

如果您是想redraw控件,做个人的设置,也是可以做到的,但是会有点复杂。你需要从C1TextBox里继承,然后处理WM_PAINT, WM_NCPAINT,以及OverriddenWndProc方法来处理其他的消息。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部