1

Firstly, I apologise if this is a 'silly' question. I have searched extensively and cannot find an answer to this, but it seems like something that should be fairly simple.

I have a Windows Forms application that has some controls for which I want to set the modifier to public: static. This is not an option in designer view (it has public, public protected, etc.). I go to the code and change, for example,

public: System::Windows::Forms::ProgressBar^ progressBar1;

to

public: static System::Windows::Forms::ProgressBar^ progressBar1;

but if I modify anything in designer view, the "public" modifier overwrites my changes to the code. It is easy to keep going back to the code and changing it if need be, but this is very time consuming.

It doesn't seem to be the sort of question that requires showing a lot of code, but if you want to see any of my code, just ask and I'll happily post it.

Thanks in advance for any help.

Anthony
  • 12,177
  • 9
  • 69
  • 105
Zac-K
  • 550
  • 5
  • 17
  • I'm not exactly sure but `static` is not really an access modifier so you might want to search somewhere else in the designer for a field where you can specify it to be `static`. – Excelcius May 07 '13 at 05:02
  • 4
    It's a control in a window. Why do you want it to be static ? – silvesthu May 07 '13 at 05:03
  • 4
    There is absolutely no reason to make a control static. Maybe you can describe your original problem, why do you need this. – Alex F May 07 '13 at 05:10
  • @silvesthu: It's a gui for what used to be a console application. I want to be able to update it from within my main function, which is impossible unless it's set to public: static (as far as I know). I know this is supposedly really bad design, but I don't know of another way to do what I need to do without spending six months restructuring the entire code. I'm really new to GUI design, so I'm probably doing all sorts of things wrong. I've been working on the console app for a couple of years, but only just started building the GUI for it. – Zac-K May 07 '13 at 05:24
  • 3
    @BZ1 'impossible unless it's set to public: static', this bit is wrong I think. You create an object of this class somewhere (that object can be static if you like) and use the object to access the progress bar. – john May 07 '13 at 05:49
  • @john: okay, thanks. That sounds promising. The programming I have been doing up to this point has been purely procedural, so I really don't know how to do that, but hopefully I can work it out. – Zac-K May 07 '13 at 08:39
  • I found a solution here: http://social.msdn.microsoft.com/forums/en-US/Vsexpressvc/thread/dcc8228d-6937-450d-b4e2-e833fb1f388b/ I'm guessing that's roughly what you were suggesting @john. Anyway, it seems to be working. I'll update after some testing. – Zac-K May 07 '13 at 08:55
  • @BZ1 Yep, something like that, there are many variations. – john May 08 '13 at 08:32
  • @john: okay, cheers. By the way, I'm pretty new here, so not sure on the etiquette. Do I post an answer to my own question with the link to the solution? It seems to be working perfectly. – Zac-K May 08 '13 at 09:57
  • @BZ1 I've seen that done before – john May 08 '13 at 10:10

1 Answers1

0

So it turns out that setting the control itself to static is not desirable, and there probably is no way to prevent VS from removing "static" from the code. I found a solution that solves my problem (which is that I wanted to access/modify the form's controls from another function) here:

http://social.msdn.microsoft.com/forums/en-US/Vsexpressvc/thread/dcc8228d-6937-450d-b4e2-e833fb1f388b/

Zac-K
  • 550
  • 5
  • 17