public DlgCommInfo() { System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false; InitializeComponent(); Init(); } public delegate void ThreadDelegateHandler(); public static event ThreadDelegateHandler ThreadHandleEvent; //事件触发方法 public static void OnTestEvent() { if (ThreadHandleEvent != null) ThreadHandleEvent(); } public static void ButtonDisable() { button1.Enabled = false; btnHide.Enabled = false; } public static void ButtonEnalbe() { button1.Enabled = true; btnHide.Enabled = true; }
最近需要用线程控制form中的显示问题,最后的解决方案是,将控件设置成static,利用事件机制进行触发。另外因为framework安全问题,需要设置
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
原文地址:http://www.cnblogs.com/ykwang/p/3833377.html