Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MDI Forms

Status
Not open for further replies.

danielkelly

IS-IT--Management
Aug 13, 2006
28
0
0
AU
Hoping someone can provide some assistance with an MDI application I am creating.

Basically i have a parent container and my first child form is a login form where the user enters their logni credentials. This is done by

frmLogin form1 = new frmLogin();
frmLogin.mdiParent = this;
frmLogin.Show();

The problem I am having is that when the user logs in successfully, i want to take them to the Main Menu which is simply a form with a few buttons on it. The question I have is how do I set the mdiparent of the new form to be the main form and not the login form??

I cant use frmMainMenu.mdiParent = this; because that references the frmLogin form not the frmMainParent (the MDI container). I thought using

frmMainMenu.mdiParent = frmMainParent but this generates a error.

Can anyone provide any assistance?? I know i will run into this problem again, because the Main Menu will spawn other Child Forms which will need their Parent Set to the Main Container and not the Form that is is called from.

Thanks in advance

 
why not use a callback function let frmMainParent create the mainmenuform ?
 
Can you provide a code snippet or sample code so i can understand what to do.

Thanks
 
how about this:

frmMainMenu.MdiParent = this.MdiParent;

when you tried this:

frmMainMenu.mdiParent = frmMainParent;

you were try to set the MdiParent to the TYPE frmMainParent not the instance of it, remember the difference.
 
Thanks, that works like a treat.

How would I go about checking if a particular form is already open?? If a user minimizes one of the MDI children forms, and then clicks on the main menu to open it. I dont want it to open a new form but restore the minimized version.

Thanks..
 
Hi,
you can iterate the child forms via MdiChildren property of the parent form, then test for each open form if the type matches the form type in concern.
Code:
void menu_click(...)
{
  foreach(Form frm in this.MdiChildren)
  {
    if(frm.GetType() == typeof(FrmChild))
    {
      [COLOR=green]// already open; maximize the form[/color]
      return;
    }
  }
  
  [COLOR=green]// create a new instance then show[/color]
}
 
Now that i have all the above working the issue i have found is with regards to Form Size.

My Main menu Bar is a small form that looks like a toolbar. When i click on one of the buttons on the bar it opens up a form which i have set its WindowState to Maximised. When I close this form down, the Main Menu Form is Maximised as well.

I am trying to figure out how to be able to Maximise one child form without Maximising them all.

Any help would be muchly appreciated.
 
I've used this code to maximize a single MDI Child form. This code runs from a menu selection on the parten.



Code:
Form importForm;
private void mnuImportData_Click(object sender, EventArgs e)
        {


            importForm = new frmImport();
            importForm.MdiParent = this;
            importForm.WindowState = FormWindowState.Maximized;
            importForm.Show();               
           
            
        }
 
I need to perform a spell check next time ;)

parent not parten

Also, ensure that you set the child form's Window State to "Normal" in the property sheet.
 
That i what i currently have but it isnt working :

Here is my exact code :--

frmPCRStatus form1 = new frmPCRStatus();
form1.MdiParent = this.MdiParent;
form1.StartPosition = FormStartPosition.CenterScreen;
form1.WindowState = FormWindowState.Maximized;
form1.Show();

With this code, the underlying Main Menu Toolbar is always maximised when the New Form is maximised.

Any further advise would be appreciated.

Thanks..
 
If you dont mind, could you give me a brief example.. I have never heard of a Singleton and how it is used.

Regards,
Daniel.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top