Frage

We're using MDI for our program.

Yes, I know, use something else, MDI is bad etc etc...the client is more comfortable with the MDI style of UI so we're sticking to that. So far we have found no need for anything like TDI or SDI anyway.

The one thing we would like to be able to do is to automatically size an MDI child to be half of the MDI client area's size; kind of similar to how in Windows 7/8 you can drag a window to one side of the screen and it will resize it to fill half of the desktop.

How can I do this?

To clarify, I'm not looking for docking, and obviously resizing a form is easy enough, I'm more interested in how to catch when the user drags the form to the edge of the MDI client area, and somehow centralising that logic so I'm not duplicating it in every form. Showing an outline of where the form will end up would be pleasant as well (again, similar to Win7/8 resizing).

Thanks

War es hilfreich?

Lösung

You are in for a world of hurt.

But here is how to get started:

Form f = new Form();
f.ResizeEnd += f_ResizeEnd;
f.MdiParent = this;
f.Show();

void f_ResizeEnd(object sender, EventArgs e) {
  MdiClient mc = this.Controls.OfType<MdiClient>().First();
  Form f = sender as Form;
  if (f.Right >= mc.ClientSize.Width) {
    f.SetBounds(mc.ClientSize.Width / 2, 0,
                mc.ClientSize.Width / 2, mc.ClientSize.Height);
  }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top