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

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#?


Designer code is not supposed to be user modified, as it gets re-written by Visual Studio every time you make changes to your form in the designer (as you have discovered).

One way forward it to move the control declaration and initialization to the non designer code file. However, that means your control will no longer appear in the designer.

Edit: This is not the way to make your controls accessible to other threads! I can't think of a valid reason to make the control static.


Wayne,

  1. No, you don't want a Control to be static. Explain why you think you do and we can find out what the better alternatives are.

  2. Don't edit in *.Designer.cs files. The tools (Forms/Dataset/... designers) have the right to overwrite everything.

Edit:

You have 2 problems to solve,

  1. Accessing the Control from another class. This should be done by passing an instance-reference to that other class. Something like:
    void Form1_Load(..) { otherObject.Form = this; }

  2. Using the Control form another thread. You can never do so directly, always use Control.Invoke(). Divo lists 2 useful links.

Tags:

C#

Modifier