0

I have two forms. One is a MDI/parent form and the other is a child form. Parent form has a few controls like label, textbox, button, etc. When I click on a button in the parent form, child form is brought in front of the parent form. But all the controls in the parent form become invisible. I want all the controls in parent form to remain visible when I open the child form. How can I achieve this?

        MdiClient client;
        Form2 myform;
        public Form1()
        {
            InitializeComponent();          

            IsMdiContainer = true;            
            client = Controls.OfType<MdiClient>().First();
            client.GotFocus += (s, e) =>
            {
                if (!MdiChildren.Any(x => x.Visible)) client.SendToBack();
            };    
        }


private void ShowForm(Form childForm)
        {
            client.BringToFront();
            childForm.Show();               
        }

 private void button1_Click(object sender, EventArgs e)
        {
            myform = new Form2() { MdiParent = this };
            ShowForm(myform);
        }
Mothy
  • 406
  • 1
  • 7
  • 19
  • Hello! I have removed the C# tag from your question's title (and fixed a few typos), but looking at your code it seems your indentation is off - feel free to re-edit your post :) – Mathieu Guindon Aug 30 '13 at 00:50
  • 1
    Just remove the client.BringToFront() call. Get rid of the GotFocus event handler as well. The proper way to do this is by docking a panel to an edge of the parent and put controls on that panel. – Hans Passant Aug 30 '13 at 01:19
  • @retailcoder : Thank you for editing.But it seems like not much changes you have done.. :) – Mothy Aug 30 '13 at 01:23
  • @HansPassant : If i remove the client.BringToFront() then i wont be able to see the child form infront of the parent form. "Docking a panel to an edge of the parent and put controls on that panel"- Could you please explain? – Mothy Aug 30 '13 at 01:27
  • Drop a panel on the parent form. Set its Dock property to, say, Left. The MDI client window shrinks to take the remaining space. Don't cover it with any other controls. – Hans Passant Aug 30 '13 at 01:29
  • @Mothy until you have > 2000 rep, *suggested edits* must be reviewed by the community (by users with > 2000 rep). Edits that are too drastic / change too much of a post (especially code) have a great deal of a better chance of getting rejected :) – Mathieu Guindon Aug 30 '13 at 01:32
  • @Mothy You could set the `StartPosition` property of the child form to center parent –  Aug 30 '13 at 07:02

0 Answers0