Hi i am having 2 forms on a application, and want to use one form to set a label in a an other form, i looked around for an answer, but i didn’t got it working. code:
form 1
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void uit_Click(object sender, EventArgs e)
{
Form2 frm = new Form2(this);
frm.Show();
}
public string LabelText
{
get { return uit.Text; }
set { uit.Text = value; }
}
}
form 2:
public partial class Form2 : Form { private Form1 mainForm = null; public Form2(Form callingForm) { mainForm = callingForm as Form1; InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { txtmessage.Text = this.mainForm.LabelText; } public void button1_Click(object sender, EventArgs e) { this.mainForm.LabelText = txtmessage.Text; } }
could someone explain why this doesn’t work?
I’ve just built it and it works fine. I’m assuming that you’ve got the events hooked up?