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;ide