Link to home
Start Free TrialLog in
Avatar of ITMikeK
ITMikeKFlag for United States of America

asked on

How do I keep a MDI winform active?

I have a MDI menuControl frame that runs the enclosed code to control the opening and closing of forms.  My problem is that once the menu selection is clicked on. the correct form loads, but the only code behind that runs is the form constructor and then it returns to the parent MDI form.  It doesn't run the form Load() or anything else.  I need it to effectively "run" the selected form until the user selects another menu item or exits the app.  How can I do this?  Thanks!

 public void getForm(string node)
        {
            //  string node = e.Node.ToString();
            switch (node)
            {
                case "Time Entries":

                    frmTimeEntries objTimeEntries = new frmTimeEntries();
                    objTimeEntries.MdiParent = this;
                    this.panel2.Controls.Add(objTimeEntries);
                    objTimeEntries.Show();
                   

                    break;
                  default: 
                      break;
          }

        private void timeEntriesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            itemname = "Time Entries";
            closeform();
            getForm(itemname);
        }


        //This is the only code that gets executed before it returns back to the code above.

        public frmTimeEntries()
        {
            InitializeComponent();
        }

Open in new window

Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

I tried but I haven't your problem.
But it crashes on the

              this.panel2.Controls.Add(objTimeEntries);

line. You do not need to add your MDI form to controls...

http://www.codeproject.com/Articles/3553/Introduction-to-MDI-Forms-with-C
Avatar of ITMikeK

ASKER

But once I open the child form, there are a bunch of controls (like a BindingNavigator), that doesn't get a chance to populate.  There are are also several drop downs that need to populate.  Should all of this be done in the child form constructor?  From what I can tell, the control focus returns to the parent form once the child constructor completes.  Make sense?
Avatar of ITMikeK

ASKER

This is a very urgent issue.  Any help will be greatly appreciated!
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ITMikeK

ASKER

Idle_Mind,

    You were correct!  My event handler for the Load was not correct (what happens when you cut and paste while fatigued!).  Thank you.  Look for my next question title "How do I keep the menu bar in focus at all times".
Avatar of ITMikeK

ASKER

Idle_Mind,

    You were correct!  My event handler for the Load was not correct (what happens when you cut and paste while fatigued!).  Thank you.  Look for my next question title "How do I keep the menu bar in focus at all times".
Just in case - was I correct about the following line? :)

       
     this.panel2.Controls.Add(objTimeEntries);

Open in new window