Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Focus a child form from MDI form .net 2.0 using c#.

Author: DevAsp Team
Download Source Code : 695_trackOpenForms.zip

In this simple article you will learn how Focus a child form from MDI form.

Simply just create New Project in C#.

 

Create three forms.

Firstly make IsMdiContainer bit True of form1 and drag a menu strip on it.

Now create three main menu open, focus and exit.

 

Now create sub menus

 

Openàform2

Open àform3

 

Focusàform2

Focusàform3

 

Exit

 

First create Global variables on Form1

 

 

Form2 frm2;

Form3 frm3;

 

Now just write Code on Sub menu to understand how we can focus on child forms

 

 

First on OpenàForm2

 

private void form1ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            frm2 = new Form2();

            frm2.MdiParent = this;

            frm2.Show();

        }

 

Then On Openàform3

 

 

private void form3ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            frm3 = new Form3();

            frm3.MdiParent = this;

            frm3.Show();

        }

 

Then on focusàfrom2

 

private void form2ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            try

            {

                frm2.Focus();

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

        }

 

Now on focusàfrom3

 

 

  private void form3ToolStripMenuItem1_Click(object sender, EventArgs e)

        {

            try

            {

                frm3.Focus();

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

        }

 

Now on Exit

 

 

private void closeToolStripMenuItem_Click(object sender, EventArgs e)

        {

            Application.Exit();

        }

Article Comments
I use the same code but when i open a child form ,it does show. but if make the mdiparant property false it shows.
pls help me.

Posted on 8/20/2007 2:06:37 PM by Rajiv Kumar

lots of thanks for give code for any one . u ans is good
put more code for help some one in application

santosh

Posted on 8/21/2007 3:28:39 AM by San

hi, this article is good. i need a help. i have a mainmenu control in my form child form. when i invoke it using MDI from that menu item is getting displayed as MDI forms menu. i want the menu to be in child form.. how could i do that?

Posted on 1/22/2008 5:37:36 AM by prema

show the coding of login form and after that how it will see the main Mdi form
thanks

Posted on 9/23/2008 2:09:56 AM by pardeep

Thanks for solutions......This solution is very useful........

Posted on 12/2/2009 8:27:37 AM by Aniket

Nice tutorial...thanx a lot.

Posted on 1/4/2010 1:46:25 AM by Amit

Thanx a lot

Posted on 2/16/2010 1:17:17 AM by abhay

thanks for this code ,,,,,,,,,

Posted on 5/15/2010 12:48:37 PM by harry

thanks for giving code am verymuch pleassure to get a code for creating mdi forms

Posted on 6/1/2010 1:42:00 AM by javed

Its realy so helpful.

Posted on 7/18/2010 12:31:23 PM by Vandy agrawal

i have facing one problem i have one mdiContainer form and one another child form (CompanyForm) which load at the time of mdiContainer loads. now whai i want is whenever i open any other child form the CompanyForm should close and if i close the new child form the CompanyForm automatically open can u please help me thanku?

Posted on 8/9/2010 10:59:45 AM by deepak bisht

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Use Dock property of controls in .net 2.0 using c#.

Disclaimer - Privacy
© 2002-2017 DevASP.net