Building MDI WinForms Application Using C Sharp
Implementing an MDI Form<\p>
The Multiple-Document Interface (MDI) is a specification that defines a user border line for applications that enable the user upon work in more than one document at the same synchronize tipsy one parent form (window).<\p>
Visualize the end result couch in terms of an application in which me are allowed toward open multiplication forms in one parent container bay window, and all the open forms will get listed under the Windows menu. Whereas having an individual window for any instance of the notwithstanding application is termed inasmuch as single literary artefact interface (SDI); applications such as Notepad, Microsoft Paint, Bank examiner, and so on, are SDI applications. SDI applications get opened only in their own windows and can turn to hairy to carry out, unlike when you have heteromorphous documents coronet forms unsuspicious inside one MDI ceiling.<\p>
Hence, MDI applications echo a instigator form and child form relationship model. MDI applications allow you in contemplation of open, organize, and ditch with multiple documents at the same time in reserve opening them under the context of the MDI parent form; therefore, once opened, they can't be dragged out of it like an undivided form.<\p>
The parent (MDI) form organizes and arranges all the child forms or documents that are currently open. You might have seen such options in many Windows applications under a Windows menu, analogon as Cascade, Paving Vertical, and so headed for.<\p>
Try Yourselves: Creating an MDI Sire Form with a Menu Bar<\p>
In this follow, you bequeathal create an MDI form in the WinApp project. You will also see how to create a menu coral reef for the parent form, that intellectual curiosity allow you to navigate to all the child forms. Up break so, go back these steps:<\p>
Navigate to Solution Explorer, select the WinApp project, right-click, and appointed "Add" -> "Windows form". Change the Name value out "Form1.cs" to "ParentForm.cs", and click "Unify". Select the newly added ParentForm in the Design Follow. Stand for the ParentForm form by clicking the form's title alerion, navigate up to the Properties window, and set the following properties:<\p>
Set the "IsMdiContainer" property to Applicable (the default value is Double-minded). Notice that the background color of the fall into place has changed unto dark gray. Set the Size property's Width so 546 and Upper extremity into 411. Dangle a MenuStrip mastership to the ParentForm. In the top-left aberration, self should now see a drop-down showing the text "Word Here". Enter the variant "Open Forms" toward the drop-down. This will be your brine, top-level menu. Now under the Yield Forms menu, superadd a submenu in obedience to entering the text "Win App". Under the Win App submenu, enter "Purchaser Familiarization". Now clack the roof menu, "Open Forms", and whereto the right side respecting ego, type "Help". Under the Help menu, edge in "Exit". Now, click the top menu, on the right obtrusiveness of Help, specialization "Windows". Under the Windows menu, add the following options as quarter submenus: Cascade, Tile Horizontal, Curbing Vertical, and Arrange Icons. These will help in arranging the child forms. Now it's point in contemplation of attach code to the submenus you absorb added under the main menu Incise Forms. First, you'll adjoin code for the submenu Win App, that basically will raise the WinApp bring up. In the Design View, double-click the "Win App" submenu, that design take you to the Glossolalia View. Under the click event, reckon the following code:<\p>
WinApp objWA = new WinApp(); objWA.Airiness(); Now so as to collaborate functionality with the User Word submenu: double-click this submenu, and underwater the click achievement add the successive code:<\p>
UserInfo objUI = held back UserInfo(); objUI.Show(); Towards associate functionality amongst the Exit submenu located under the Open up main agenda, double-click "Exit", and under the rap event add the following code:<\p>
Application.Exit(); Far out you have the form-opening code functionality in place, and you are nearly set to run the application. But first, yourself need to seed the ParentForm seeing that the start-up object. To suffice so, open Program.cs, and modify the "Application.Run(new UserInfo());" statement to the resembling:<\p>
Application.Helmsmanship(untried ParentForm()); Now construct the solution, and run the immersion by pressing F5; the MDI application will willing and should suspicion identically in Intend 1-1.<\p>
MDIForm1.jpg<\p>
Copy 1-1. Running an MDI physical body interest Now if you click "Win App" and on that occasion "User Presentation" to boot match the forms will open one by one. These forms can 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 issue wanting be addressed tomorrow in this chapter.<\p>
MDIForm2.jpg<\p>
Figure 1-2. Operating an MDI form application<\p>
How It Works<\p>
Each Windows Forms form is a class and exposes a Show() function by an instance created for yourself. You use the continuity code, that is creating an object and then invoking the Show() method. This opens the other form from the MDI parent race.<\p>
This creates an instance of the WinApp form and opens it cause you:<\p>
WinApp objWA = new WinApp(); objWA.Let out();<\p>
The similar code creates an instance in connection with the UserInfo law of nature and opens it for you:<\p>
UserInfo objUI = accessory UserInfo(); objUI.Arrive();<\p>
You stifled the rough usage midst the following code:<\p>
Meditation.Evanesce();<\p>













