hi friends,
I want to refer control from previous page in windows form application. On the form1 i have a textbox1 and listbox1 and form2 contain two label as label1 and label2. On the loading of form2 i want display the result of textbox1 on label1 and the result of listbox1 on label2.
I tried below code :
------------------------------------Form-1----------------------------------------------
namespace msg
{
public partial class ToReferControlFromPrevPage_prev_page_ : Form
{
public ToReferControlFromPrevPage_prev_page_()
{
InitializeComponent();
}
//private void ToReferControlFromPrevPage_prev_page__Load(object sender, EventArgs e)
public void ToReferControlFromPrevPage_prev_page__Load(object sender, EventArgs e)
{
listBox1.Items.Add("Emp id : a_108");
listBox1.Items.Add("Age 24");
listBox1.Items.Add("Post: Developer");
listBox1.Items.Add("mob : 9977668018");
listBox1.Items.Add("Add : Indore");
}
//private void textBox1_TextChanged(object sender, EventArgs e)
public void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
----------------------------------------Form-2------------------------------------------
namespace msg
{
public partial class ToReferControlFromPrevPage_next_page_ : Form
{
public ToReferControlFromPrevPage_next_page_()
{
InitializeComponent();
}
private void ToReferControlFromPrevPage_next_page__Load(object sender, EventArgs e)
{
ToReferControlFromPrevPage_prev_page_ p1 = Application.OpenForms ["ToReferControlFromPrevPage_prev_page_"] as ToReferControlFromPrevPage_prev_page_;
label1.Text = p1.textBox1.Text;
}
}
}