|
-
July 25th, 2011, 04:40 AM
#1
Multiple Forms W/ Passing Value Problem
I'm currently working on a project on GUI with math model. I'm a Math student and my programming knowledge is limited. I need some helps on my program design.
//In the Form1, I have
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public double contactR;
private void button1_Click(object sender, EventArgs e)
{
if (rdButton1.Checked)
{
contactR = 0.1;
}
else if (rdButton2.Checked)
{
contactR = 0.2;
}
else if (rdButton3.Checked)
{
contactR = 0.3;
}
else if (rdButton4.Checked)
{
contactR = 0.4;
}
Form2 secondForm = new Form2(contactR.ToString());
this.Hide();
secondForm.Show();
}
}
// I pass a string Form 2 and here is the source code
{
public Form2(string contactR)
{
InitializeComponent();
}
public double infectiveR;
private void button1_Click(object sender, EventArgs e)
{
if (rdButton1.Checked)
{
infectiveR = 0.33;
}
else if (rdButton2.Checked)
{
infectiveR = 0.25;
}
else if (rdButton3.Checked)
{
infectiveR = 0.20;
}
else if (rdButton4.Checked)
{
infectiveR = 0.17;
}
else if (rdButton5.Checked)
{
infectiveR = 0.14;
}
else if (rdButton6.Checked)
{
infectiveR = 0.10;
}
Form3 thirdForm = new Form3();
this.Hide();
thirdForm.Show();
}
}
-----------------------------------------------------------------------------------------------------
If I add a MessageBox.Show(contactR); in
public Form2(string contactR)
{
InitializeComponent();
}
It works well and it shows that value that I choose in Form1.
However I would like to know is there any method to pass the string contactR from "public Form2(string contactR)" to "private void button1_Click(object sender, EventArgs e)"?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|