Alot of Searching, a Little Intuition
I have been laboring over the past few weeks trying to get a progress bar control to be static. The problem originates from the fast that I am using Microsoft Visual Studio 2005 to code my project and I, like most mortals, am unable to resist the lure of Drag-N-Drop design. Once you drag a tool from the toolbox onto the form, the Designer writes all of the code behind to configure and add that control. For most uses, the properties pane is enough to modify the object to do what you need. What if you need the object to be static, however?
Here is a little background on my project. I have developed an application that will allow me to upload large files to my web host in small chunks. I decided to place a majority of the work inside a class that inherited from a background worker so that my application wouldn't freeze up on me. My next choice was to implement a progress bar to let me know how far into the upload my file was. Since the background worker class was not a part of my form, it could not directly access my progress bar and needed a function. Also, since my background worker class did not contain a form object, I had to make the function and progress bar static.
The result is that I would go into the designer generated code and modify the progress bar to be static. Everything would work fine until I did anything to the form. This would cause the designer to rewrite its code, and overwrite mine. More can be read about this issue here. I did a ton of searching on the net to find a way to force the designer to make the variable static. I was pondering the issue a little while ago and the answer dawned on me. I went into the designer code and located the declaration of the variable:private System.Windows.Forms.ProgressBar progressBar1;
I cut it out of there and pasted it into the top of my partial Form1 class, only this time, making it static. From there, I merely needed to go back into the designer code and remove the this. tag from all of the definitions of progressBar1. Problem solved! From then on, the designer rewrote the progressBar code to be static.
Now I am going to write a bunch of random words in hope that anybody who is searching for this answer like I was will find it:
changing designer generated code
making VS2005 objects static
Designer winforms static
forcing designer generated objects to be static
