Child form implement in C# Winform

2k views Asked by At

Well, I'm writing a simple application which will have multiple forms inside it. Now say one form will be the base window i.e. the parent and all other will be child of it. So for this I'm trying to opening the child window by below method.

//Inside class FormBaseWindow

private void linkLabelReservation_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
  Point childLocation = new Point(this.Location.X + 100, this.Location.Y + 120);
  FormReservation formReserve = new FormReservation();
  formReserve.Location = childLocation;
  formReserve.MdiParent = this.MdiParent;
  formReserve.Show();
}

And also set the IsMdiContainer attribute of FormBaseWindow class to true. Now the things is, I want to have feel like dragging the FormBaseWindow window will drag the whole thing including the child window inside it. Currently once I click on the FormBaseWindow window its coming foreground and the child is going behind it.

In MFC I was able to do it by setting the window style Child and set it as a child window, but here the story is bit different.

I'm using C# Winforms with VS 2012.

1

There are 1 answers

4
Raging Bull On BEST ANSWER

Change :

formReserve.MdiParent = this.MdiParent;

to

formReserve.MdiParent = this;

NB: You should use

formReserve.MdiParent = this.MdiParent; 

when you open a child form from another child form to make it under the same MdiParent.