Hi,
I have two form i my project. Form1 contains a text box with public access modifiers and a button.
and Form 2 contains a label and a button.
the following task i am trying to do.
when some one enter some text in text box and click the button it will show the form two and its bit easy task.
But the problem is that I want to access the values of text box(Form1) to Form2 when i will click the button on form 2 but getting error the code is
I have two form i my project. Form1 contains a text box with public access modifiers and a button.
and Form 2 contains a label and a button.
the following task i am trying to do.
when some one enter some text in text box and click the button it will show the form two and its bit easy task.
But the problem is that I want to access the values of text box(Form1) to Form2 when i will click the button on form 2 but getting error the code is
Code:
//Form1 Button Code
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
frm.Show();
}
}
//form 2 code
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = Form1.ActiveForm.Controls["textBox1"].Text.ToString();
}
}
Comment