Hi All, I'm very new to c#, programming in general :-)
I'm trying to do a simple test and its failing, hopfully you guru's can answer it in a jiffy...
Setup:
- Form1 with toolstrip and toolstriplabel with value "TEST"
- Form2 with a Button
Test: Button press will change the label value on Form1 toolstriplabel to "PASSED";
Here is the code... [not working]
Here is Form2
I'm getting NullReferenceEx ception... What do I need to instantiate?
I'm trying to do a simple test and its failing, hopfully you guru's can answer it in a jiffy...
Setup:
- Form1 with toolstrip and toolstriplabel with value "TEST"
- Form2 with a Button
Test: Button press will change the label value on Form1 toolstriplabel to "PASSED";
Here is the code... [not working]
Code:
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Shown(object sender, EventArgs e)
{
Form2 ChildForm = new Form2();
ChildForm.ShowDialog();
}
}
}
Code:
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
Form1 MainForm = new Form1();
MainForm.Controls["toolStripStatusLabel1"].Text = "Passed";
}
catch (NullReferenceException nre)
{
MessageBox.Show("Error:\n" + nre.Message);
}
}
}
}
Comment