Take a static class Property.
class Class1
{
static string name;
static string add;
public static string PName
{
get
{
return name;
}
set
{
name = value;
}
}
public static string PAddress
{
get
{
return add;
}
set
{
add = value;
}
}
}
Now on Form1 take two textbox and two button
and write this code on .cs file.
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("Please don`t leave any textbox empty.");
}
else
{
Class1.PName = textBox1.Text;
Class1.PAddress = textBox2.Text;
Form2 f2 = new Form2();
f2.Show();
}
}
Now take another form (Form2)
Take two label and one button on it.
Now write this code on .cs file to received value from Form1 and display it.
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void Form2_Load(object sender, EventArgs e)
{
label1.Text = Class1.PName;
label2.Text = Class1.PAddress;
}