首页 > Windows开发 > 详细

C# enable为false时不变颜色

时间:2018-07-22 10:07:36      阅读:458      评论:0      收藏:0      [点我收藏+]
 1         [System.Runtime.InteropServices.DllImport("user32.dll ")]
 2         public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int wndproc);
 3         [System.Runtime.InteropServices.DllImport("user32.dll ")]
 4         public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
 5  
 6         public const int GWL_STYLE = -16;
 7         public const int WS_DISABLED = 0x8000000;
 8  
 9         public static void SetControlEnabled(Control c, bool enabled)
10         {
11             if (enabled)
12             { SetWindowLong(c.Handle, GWL_STYLE, (~WS_DISABLED) & GetWindowLong(c.Handle, GWL_STYLE)); }
13             else
14             { SetWindowLong(c.Handle, GWL_STYLE, WS_DISABLED + GetWindowLong(c.Handle, GWL_STYLE)); }
15         }
16  
17         private void button2_Click(object sender, System.EventArgs e)
18         {
19             SetControlEnabled(this.button1, false);
20             this.button1.ForeColor = Color.White;
21         }
这个操作不是直接改变Enable 而是去掉它的鼠标绑定

 

C# enable为false时不变颜色

原文:https://www.cnblogs.com/zhangruifeng/p/9349161.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!