2015.12.14 MDI (multiple file window structure) set the basic solution, tossing the day, partly solving the problem that has existed for a long time. However, the effect is still less than the MDI form structure of the temporary route.

Source: Internet
Author: User

Creating a structure that pops multiple child windows from a window is called an MDI form structure

If you do not manage by MDI structure, the simplest approach is:

Add a menu or button on form A to add a pop-up B-form code to a menu or button event:

b b = new B ();

B.show ()

So that A and B have no relationship, how many pop-up windows on the taskbar have the number of icons, the parent window minimized when the rest of the window does not change. This is more messy.

However, the advantage is that the location and size of the pop-up window has no constraint on the parent window, and the pop-up window can be displayed outside the parent window.

Slightly improved method (probably better than the one below to improve MDI)

b b = new B ();

B.show (this)//plus This indicates that the b window belongs to the a form this, so that all child windows are minimized when a is minimized, and only one icon on the taskbar is minimized. And all child windows are always in the front of the parent window and are not obscured by them. However, there will still be icons for all child windows on the taskbar.

Use the traditional MDI child window to handle the following

1. The IsMdiContainer property of the parent window is set to True (can be set by the interface)

2. The popup code for the menu or button event's child window is written as:

b b = new B ();

B. mdiparent = this; This represents the parent window

B.windowstate = formwindowstate.maximized;//

B.show ()

Note: A bug that may be a VS, all subforms can only be displayed under the parent form control, and if there is a PictureBox picture background on the parent form, all pop-up windows will be covered with the picture, as if it didn't pop up. (It took me nearly 1 hours to find out).

3 Ways to resolve:

1, the background image is set to the background of the main window, without PictureBox but this will produce flicker, not good-looking

2, pop up any child window will picturebox hidden.

3, use the API function instead of B. MdiParent = this. Written api.setparent (b.handle,picturebox1.handle); Note: The parent form of the subform is set to PictureBox instead of a! This is perfect for traditional MDI forms, but if you use the following to optimize the MDI effect is not good, only use Method 2

This completes the setup of the traditional MDI form,

This shortcoming is as obvious as the merit.

The advantage is that all forms have only one icon on the taskbar, all subforms are listed at the bottom of the parent form (three buttons to maximize, minimize, and so on), and all subforms disappear with the parent window.

The disadvantage is only 1, but it's deadly: The subform cannot move out of the parent form. Very inconvenient for large monitors or multiple displays.

Improved method: The primary workaround for the subform cannot be moved out of the parent window.

Idea: The subform is maximized by default, fills the parent window client area, but when you click Restore normal size display, exit the MDI child window mode, leaving it out of the parent window size limit and become a standalone window.

Method: After the MDI settings above, add the WndProc callback function in the popup each form, handle the Restore display event and the maximum, minimize event

Defined in the child window function:

const int Wm_syscommand = 0x112;//274

const int sc_maximize = 0xf030;//61488

const int sc_minimize = 0xf020;//61472

const int sc_restore = 0xf120; 61728

const int sc_close = 0xf060;//61536

protected override void WndProc (ref Message m)

{

if (m.msg = = Wm_syscommand)

{

if (m.wparam.toint32 () = = Sc_restore)//handles the form restore event, sets the child window parent form to the parent window of the original parent window, which is the desktop

{

This. MdiParent = MF.mf.MdiParent;

This. WindowState = Formwindowstate.normal;

System.Drawing.Rectangle rect = systeminformation.workingarea;//Get screen working size

This. Height = rect. Height * 3/4;

This. Width = rect. Width * 3/4;

This. CenterToParent ();

}

if (m.wparam.toint32 () = = sc_maximize)//Handle the form to maximize minimized events, revert to MDI mode, and write maximum, minimized

{

This. MdiParent = MF.MF;

This. WindowState = formwindowstate.maximized;

}

if (m.wparam.toint32 () = = sc_minimize)

{

This. MdiParent = MF.MF;

This. WindowState = formwindowstate.minimized;

}

}

Base. WndProc (ref m);

}

2015.12.14 MDI (multiple file window structure) set the basic solution, tossing the day, partly solving the problem that has existed for a long time. However, the effect is still less than the MDI form structure of the temporary route.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.