How to change modifier of a control to Static in Visual Studio

Wayne picture Wayne · Jan 11, 2010 · Viewed 12.9k times · Source

when i create a control by drag and drop VS automatically generate code like this:

public System.Windows.Forms.Label label1;

When i want to change modifier of that control to Static, i go to Form1.Designer.cs and edit to:

public static System.Windows.Forms.Label label1;

It's ok. But when i modify every control, VS automatically change it to origin :(. So how do you change modify of a control to static ?

sorry, im bad at English :(


code from a comment:

public static void setLabelInfoVisible(bool visible) 
{ 
   if (Form1.labelInfo.InvokeRequired) 
   { 
      setLabelInfoVisibleDelegate del =
         new setLabelInfoVisibleDelegate(setLabelInfoVisible);
      Form1.labelInfo.Invoke(del, new object[] { visible }); 
   } 
   else 
   { 
     Form1.labelInfo.Visible = visible; 
   } 
}

Answer

Dirk Vollmar picture Dirk Vollmar · Jan 11, 2010

It seems that your actual problem is another one: Updating controls from another thread. This should NOT be accomplished by static controls!

These related questions should solve your problem:

How to update textbox on GUI from another thread in c#

How to update GUI from another thread in C#?