Windows Develop Bookmark and Share   
 index > Windows Forms General > Closing mainform by childforms button
 

Closing mainform by childforms button

Hi All,

I have to forms, form1 and form2. form one is the mainform and im opening form2 to inside the tabpage1 of tabcontrol of form1:

form2.FormBorderStyle = FormBorderStyle.None;

form2.TopLevel = false;

this.tabPage1.Controls.Clear();

this.tabPage1.Controls.Add(_form2);

form2.Show();

form2 has also abutton 'cancle'. How can i close the main form(form1), by clicking the 'cancle' button of form2 ???

Thanx

Djavid  Friday, March 21, 2008 9:32 AM

Hi,

Take a look over here to see if it helps you

How to Close Parent Form from Child Form in Windows Forms 2.0

HTH,
Suprotim Agarwal

-----
http://www.dotnetcurry.com
http://www.sqlservercurry.com
-----

Suprotim Agarwal  Friday, March 21, 2008 10:22 AM

on form2 button click

this.ParentForm.Close();

DinoMulahusic   Friday, March 21, 2008 10:11 AM

Hi,

Take a look over here to see if it helps you

How to Close Parent Form from Child Form in Windows Forms 2.0

HTH,
Suprotim Agarwal

-----
http://www.dotnetcurry.com
http://www.sqlservercurry.com
-----

Suprotim Agarwal  Friday, March 21, 2008 10:22 AM
Hello,

-As said above- If I were you I would use formClosed event like

---------Parent form side-------------
private void btnOpenForm_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.FormClosed += new FormClosedEventHandler(frm2_FormClosed);
frm2.Show();
}
private void frm2_FormClosed(object sender, FormClosedEventArgs e)
{
this.Close();
}
----------Child form side-----------

private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}

Kind regards..

Sqnyy  Friday, March 21, 2008 12:01 PM

You can use google to search for other answers

Custom Search

More Threads

• UrlEncode
• Howto reduce long text to view region in the textbox with the finalize "..."
• Project References - How do I get the DLL Version Numbers
• controls in vb2005
• Regarding Menu Bar..
• Readng Bitmap Files
• How to catch multi-threading exceptions?
• Are there globalization tools like "Generate Local Resource" available for Windows Forms Applications ?
• Setup for database.
• Method in One Form is not being called from another form