Wednesday, July 4, 2012

Enable/Disable ToolstripButton using Delegates (Thread)

Assuming you will access the toolstrip button from another thread, then here's the code to do it.
Code:
  delegate void EnableDisableButtonRunDeleg(bool value);  
      private void EnableDisableButtonRun(bool value)  
      {  
        if (tsMenu.InvokeRequired)  
        {  
         this.tsMenu.Invoke(new EnableDisableButtonRunDeleg   
          (EnableDisableButtonRun), value);  
        }  
        else  
        {  
          ToolStripItem ts = tsMenu.Items[0];  
          ((ToolStripButton)ts).Enabled = value;  
        }  
      }

Cheers!

0 comments:

Post a Comment