how can i call existing form from another existing from?
hi all,
am new in c#, am doing a windows application, there is button1 in form1 i want that when button1 will be press form2 will be displayed.
form1 & form2 both are existing.
plzzz help.
sachi vasishtaPosted Jun 4, 2009, 1:56 AM
If this is the case then you double click on the button in form1 and wite the below code in the button click event
private void button1_Click(object sender,EventArgs e)
{
Form2 obj=new Form2();
obj.Show();
}
and in form2's load event write the below code
private void Form2_Load(object sender, EventArgs e)
{
Form1.ActiveForm.Close();
}
if you want to pass some values from form1 to form2 then you can go for overloaded constructor like below
private void button1_Click(object sender,EventArgs e)
{
string val1="sachi";
string val2="vasishta";
Form2 obj=new Form2(val1,val2);
obj.Show();
}
and in form2's constructor you write the below code
public string assval1,assval2;
public Form2(string recval1,string recval2)
{
InitializeComponent();
assval1=recval1;
assval2=recval2;
}
now you can use these two variables assval1,assval2 anywhere in form2.
try this
Niradhip ChakrabortyPosted Jun 3, 2009, 1:31 PM
private void btnForm1_Click(object sender, System.EventArgs e)
{
Form1 form1 = new Form1();
form1.Show();
}
You can refer the following articles for your second question:
Check Out:
1.http://www.vbforums.com/showthread.php?t=561654
2.http://www.dreamincode.net/forums/showtopic75208.htm
You also can refer the following article for more information regarding windows form:
1.http://www.codeproject.com/KB/books/1861004982.aspx
Sumanta DasPosted Jun 3, 2009, 7:51 AM