Looking for some help, if you have the time (anyone) it'd be great.
Here's the deal. I've got a windows form...dropdown list of states. If Florida is selected, I want a pop-up window to ask for a $$ amount. Then that value in the pop-up has to be stored in a variable so I can do some math on it before displaying it in a summary box.
Any idea how to do a windows pop-up, grab a value entered, and then display in a text box with something like
SummaryBox.Items.Add ("Amount entered in Florida Pop-up window: " + florida_value_entered_from_popup + ".");
//where florida_value_entered_from_popup is just a decimal variable
Thank you all again for taking the time to help out a new guy.
-Corby-
PS any good starter books out there that aren't geared towards 7th graders or MIT grads

windows forms + popup +variable value
Kandikan
I'm pulling my hair out over this. I know it's unbelievably simple but I don't have a C# book yet and the details out on the web don't seem to be helping...
I can't get form2 to show so I can input text and then pass it back to form1.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Setup is Form1 has a dropdown box, if Florida is selected, I need form2 to show. In form2, one text box for input. Do input, click OK, and that value needs to go back to form1 as a variable so I can do some math on it.
Any help for a very new guy greatly appreciated in advance!
-Corby-
iHEARTmicrosoft_BUT
class Form1 : System.Windows.Forms.Form
{
// make sure this variable is public so we can access it from Form2 public string putTheVariableHere = ""; // this is just a button click handler; this could be any handler of your choice void Button_Click (object sender, EventArgs e){
// NOTE: look at the constructor for Form2Form2 frm2 =
new Form2(this);frm2.Show();
}
}
class
Form2 : System.Windows.Forms.Form{
// use this to store a reference to the Form1 object private Form m_refToForm1 = null; // UPDATED CONSTRUCTOR: I'm passing a Form object (Form1) to this constructor so I can store a reference to it public Form2 (Form form1){
// store the reference to the form1 object so we can access it from this formm_refToForm1 = form1;
}
// handler for the "save" button or whatever handler needs to update form1 void Button_Click (object sender, EventArgs e){
// reference the "putTheVariableHere" string in form1 and store the text from my textbox on form2((Form1)m_refToForm1).putTheVariableHere = txtThisIsMyTextBox.Text;
// close this form this.Close();}
}
Phil Seastrand
Here is the code I'm using in Form1 to call open Form2. Keep in mind that I only want this pop-up to occur when the statecombo box (without having to click any buttons). This works for the pop-up.
private void statecombo_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (Convert.ToString(statecombo.Text)=="Florida")
{
Form2 newform = new Form2();
newform.Show();
}
}
So when Florida is selected, Form2 pops up. I need the value from textBox1 on Form2 to be sent to a variable in Form1 called "floridavariable". This is the part that I'm having a problem with.
I'm wondering if the first part of code you mentioned in the above post, isn't meshing with what I'm using...for example, you use the (this) in line 1 of your suggeston and if I put (this) in my above code, I get errors.
And when I try to modify your code for Form2 to work with my form names and variable names, it's tossing an error on "refToForm1"...so I'm mentally missing something there. Can you perhaps clarify what I might be able to do with the "refToForm1" piece
Thanks again for your help.
-Corby-
Scott Berry
-Corby-
dydoria
It took me a while to figure out what goes where within my all-over-the-place code (and long weekend) but after messing with it for a while, I appear to have it working. I also think I'm starting to understand passing objects with this example.
Huge help, I thank you deeply. Much appreciated.
-Corby-
Visio User
Hope that helps.
kowalsky
My question now is geared towards getting that value from textbox1 in form2 back to form1 when OK is clicked on form2.
Tnx again all. This is a very helpful community.
Ensynch
Form2 frm2 = new Form2(this);
frm2.ShowDialog();
Then you can do something like this in the button event handler on Form2:
((Form1)refToForm1).VariableInForm1 = myTextBox.Text;
this.Close();