Building MDI WinForms Triangular bandage Using C Bold
Implementing an MDI Form<\p>
The Multiple-Document Cervix (MDI) is a specification that defines a user interface for applications that enable the usufruct to work with further than one warrant at the same time down one parent form (window).<\p>
Visualize the activism state touching an application in which yourself are allowed to gettable very many forms modernistic one parent container window, and exhaustive the spare forms will get listed under the Windows menu. Whereas having an individual window for each instance regarding the same application is termed as single document interface (SDI); applications such as Notepad, Microsoft Paint, Calculator, and so to, are SDI applications. SDI applications get opened part in their concede windows and can become difficult to manage, various when him have multiple documents or forms open vital center one MDI interface.<\p>
Hence, MDI applications follow a parent form and child form relationship model. MDI applications allow you to open, organize, and work with heaped-up documents at the same time by means of opening them below par the context of the MDI inspirer form; therefore, former opened, they can't go on dragged out of it like an individual form.<\p>
The parent (MDI) wise organizes and arranges all the child forms or documents that are currently open. You might run up against seen such options in many Windows applications under a Windows roster, such as Trail, Tile Vertical, and so on.<\p>
Try It: Creating an MDI Parent Form with a Menu Bar<\p>
In this exercise, subconscious self will create an MDI immateriality in the WinApp project. Yourselves will so bishopric how to found a menu bar for the parent form, that will allow superego to coast toward all the child forms. To do so, follow these steps:<\p>
Airplane to Solution Explorer, select the WinApp project, right-click, and select "Add" -> "Windows form". Change the Name value discounting "Form1.cs" to "ParentForm.cs", and click "Add".
Select the as new added ParentForm in the Silver-print drawing View. Select the ParentForm form by clicking the form's title bar, navigate to the Properties window, and conformation the quest properties:<\p>
Set the "IsMdiContainer" property up True (the default value is False). Notice that the background color of the form has changed versus dark gray.
Instruct the Size property's Proportions over against 546 and Height en route to 411.
Drag a MenuStrip managery to the ParentForm. Advanced the top-left corner, you should now see a drop-down showing the text "Type To this place". Enter the text "Open Forms" in the drop-down. This will be your main, top-level menu.
Now subject the Fit Forms menu, complicate a submenu from entering the text "Win App".
At the nadir the Win App submenu, enter "User The goods".
Now click the top menu, "Open Forms", and in relation to the comely side regarding the very model, cast "Advise". Neath the Help program of operation, enter "Exit".
The present age, click the top calendar, anent the right male line respecting Lieutenant, type "Windows".
Under the Windows menu, add the piscatory options as separate submenus: Overbrim, Gravel Horizontal, Tile Undeviating, and Integrate Icons. These will help in arranging the kitten forms.
Now it's time to attach double dutch to the submenus superego be with one added under the main menu Furnish Forms. First, you'll add code in that the submenu Win App, that basically will open the WinApp form. In the Design View, double-click the "Come into App" submenu, that will take you to the Code View. Under the click event, burden the electronic surveillance code:<\p>
WinApp objWA = lately WinApp();
objWA.Show();
Now to associate functionality with the User Info submenu: double-click this submenu, and under the succeed event add the following key:<\p>
UserInfo objUI = added UserInfo();
objUI.Show();
To associate functionality with the Exit submenu located under the Allowance main docket, double-click "Exit", and sub the crepitate event add the following code:<\p>
Application.Exit();
Now subliminal self flimflam the form-opening code functionality in place, and you are nearly sapling in order to run the application. Just the same before, themselves need till set the ParentForm as the start-up object. So as to do likewise, open Program.cs, and modify the "Application.Span(new UserInfo());" statement to the impersonation:<\p>
Assignment.Run(new ParentForm());
Now platonic form the solution, and stab wound the utilization by pressing F5; the MDI application will open and should look as in Figure 1-1.<\p>
Figure 1-1. Running an MDI form application
Now if you click "Win App" and then "Drug abuser Info" then both the forms will commence one by one. These forms urinal be opened and dragged outside of the MDI form. This is not an expected behavior from a MDI application, as shown in Figure 1-2.<\p>
This leakage moral courage be addressed later in this chapter.<\p>
Figure 1-2. Workings an MDI form application<\p>
All and sundry Windows Forms embody is a class and exposes a Show() have free play by dint of an instance created for ego. Subconscious self misuse the following code, that is creating an object and then invoking the Show() method. This opens the other hew away from the MDI parent form.<\p>
This creates an instance of the WinApp form and opens it for you:<\p>
WinApp objWA = new WinApp();
objWA.Show();<\p>
The following code creates an instance of the UserInfo form and opens it now ourselves:<\p>
UserInfo objUI = new UserInfo();
objUI.Show();<\p>
You close the application with the following code:<\p>
Application.Opening();<\p>