Re: Not Calling Correctly
Code:
private static frmMain frmMainControl = new frmMain();
"new frmMain()" returns a frmMain object, but not the one that you are looking at when the code is run. It is created but not yet visible, it is the same as creating two integer variables, x and y, setting x equal to 10 and also expecting y to be set to 10.
Some advice; do not create classes that depend on the implementation of your form, you have it backward. Your data classes should hold data and your form class will use these data classes to store and manipulate the data, not to display it.
Re: Not Calling Correctly
I see.. so how do I call my already created frmMain?
And thanks.. I'll try to work through that..
Re: Not Calling Correctly
I would reiterate that holding a reference to your main form in another class is a terrible design and is often what most beginners will jump to because it is easier (I did :)). I suggest that you read into using events for passing information between classes.
Re: Not Calling Correctly
Alright.. well as far as buttonToMenu variable is concerned, is there a way to constantly pass it? For example.. I've got 6 different buttons that all call the conextMenuStrip when clicked. Is there a way to tell the contextMenuStrip WHICH button caused it to show up, so that when an option on the menu is clicked, I know which button it came from?
A "roll" button is pressed. When the roll button is pressed, it generates 6 random numbers. The 6 random numbers are dispersed to each button (1 number to each button). What is supposed to happen is when button1 is pressed, a context menu pops up with several options. Each option assigns it to a different text box. Once it is clicked, the corresponding text box gets the number and the button.text is cleared.
However, if button 2 is pressed and sent to a text box that already has a value in it, then the value in that text box and the value on the button need to switch places.
In play:
Button1 Clicked -> Context Menu shown -> "Strength" option selected. txtStrength.Text obtains Button1.Text value.
Button2 Clicked -> Context Menu shown -> "Strength" option selected. txtStrength.Text obtains Button2.Text value, while Button2.Text obtains txtStrength.Text value.
The only way I see being able to do this is having a holding variable that is filled when a button is clicked (so that when the values from text box to button is switched, I know where its going) or to create 6 different context menus with the same items. Either seems redundant. Do you know a better way to do this? I'm always open for suggestions.