Visual C# Developer Center > Visual C# Forums > Visual C# General > How can I open a child window and block the parent window only?
Ask a questionAsk a question
 

AnswerHow can I open a child window and block the parent window only?

Answers

  • Friday, September 09, 2005 7:33 AMJames KovacsMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    What about disabling the parent form while the child form is active? When the child form is created, set its owner to this:

    ChildForm child = new ChildForm();
    child.Owner = this;
    child.Show();

    In ChildForm_Load:
    private void ChildForm_Load(object sender, EventArgs e) {
      this.Owner.Enabled = false;
    }

    private void ChildForm_Closed(object sender, EventArgs e) {
      this.Owner.Enabled = true;
    }

All Replies

  • Friday, September 09, 2005 7:33 AMJames KovacsMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    What about disabling the parent form while the child form is active? When the child form is created, set its owner to this:

    ChildForm child = new ChildForm();
    child.Owner = this;
    child.Show();

    In ChildForm_Load:
    private void ChildForm_Load(object sender, EventArgs e) {
      this.Owner.Enabled = false;
    }

    private void ChildForm_Closed(object sender, EventArgs e) {
      this.Owner.Enabled = true;
    }
  • Wednesday, November 04, 2009 11:51 PMReggieH Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    WinXP
    VS2008 sp 3.5
    C#

    I was having a similar issue, and the code above helped me. The one problem I am still having is that the child window does not center in the parent window???? I went in VS and changed the Start Position of the Child form to Center Parent, but that does not work either. It will go to the upper left corner.

    I would like the child window to stay inbounds of the parent bounds.

    Any suggestions on how to accomplish?