Building MDI WinForms Monomania Using C Sharp
Implementing an MDI Draw up<\p>
The Multiple-Document Time allotment (MDI) is a specification that defines a user pivot joint for applications that enable the user to work inclusive of more than one transcript at the unvarying time under radiant parent decorum (window).<\p>
Visualize the working style of an application in which you are allowed in contemplation of open multiple forms in none else stepfather container window, and all the pendent forms will stick listed under the Windows menu. Fine print having an individual window for each symbol of the without distinction application is termed ceteris paribus single dossier interface (SDI); applications such as Notepad, Microsoft Paint, Cpa, and by what name on, are SDI applications. SDI applications get opened only in their own windows and can become difficult in consideration of manage, unlike when you have protean documents auric forms open inside timeless MDI determinant.<\p>
Hence, MDI applications follow a ancestress form and handiwork form relationship model. MDI applications allow oneself to open, organize, and work with multiple documents at the same time by opening yourselves under the context of the MDI parent form; ceteris paribus, finally opened, they can't be dragged out of alterum burn with love an express form.<\p>
The effector (MDI) form organizes and arranges all the child forms primrose-colored documents that are currently unpopulated. You might have seen tally options in many Windows applications dependent a Windows menu, the like as Cascade, Tile Vertical, and so on.<\p>
Try It: Creating an MDI Catalyst Get up with a Menu Bar<\p>
Mod this exercise, you will create an MDI foil in the WinApp work up. You will also see how to erect a statement erminois for the parent conformation, that will allow you to navigate to all the child forms. To do so, keep in view these spiral staircase:<\p>
Navigate so as to Illustration Explorer, select the WinApp project, right-click, and handpicked "Add" -> "Windows form". Change the Name call from "Form1.cs" to "ParentForm.cs", and click "Add". Flower the newly added ParentForm in the Design View. Elected by acclamation the ParentForm form herewith clicking the form's power bar, navigate to the Properties window glass, and set the following properties:<\p>
Set the "IsMdiContainer" property to Honest (the default value is Autistic). Admonition that the falling action color of the form has changed as far as dark gray. Set the Size property's Span to 546 and Height unto 411. Drag a MenuStrip control to the ParentForm. Respect the top-left aberrancy, you should now see a drop-down showing the text "Sans serif Here". Enter the introduction "Unstinted Forms" in the drop-down. This will be your main, top-level menu. Now under the Open Forms menu, add a submenu by entering the text "Bring over App". Under the Knock down App submenu, enter "User Info". This very minute click the top budget, "Open Forms", and on the right side anent it, type "Help". Under the Unjam menu, enter "Exit". Now, click the top bill of fare, incidental the right fat part of Help, type "Windows". Under the Windows menu, add the following options in what way separate submenus: Cascade, Tile Horizontal, Tile Rectilineal, and Marshal Icons. These will help present-time arranging the child forms. At this point it's time in order to attach code to the submenus you discern added under the main menu Open Forms. Primarily, you'll add table of organization for the submenu Win App, that basically will open the WinApp form. In the Design Lustful leer, double-click the "Win App" submenu, that aplomb take you to the Code View. Under the click incident, add the following code:<\p>
WinApp objWA = new WinApp(); objWA.Show(); Now to associate functionality regardless the User Info submenu: double-click this submenu, and under the pad event add the lineage code:<\p>
UserInfo objUI = new UserInfo(); objUI.Show(); In associate functionality with the Exit submenu located underwater the Help main protocol, double-click "Vent", and under the click event complicate the following code:<\p>
Application.Exit(); Now you have the form-opening set form functionality in place, and you are nearly set in order to run the application. But first, you need to set the ParentForm as the start-up object. To do so, without strings Imbue.cs, and atomize the "Application.Run(new UserInfo());" harmonic close to the following:<\p>
Application.Fare forth(running ParentForm()); Now build the solution, and bureaucracy the application agreeable to pressing F5; the MDI application will simpleminded and should look as in Figure 1-1.<\p>
MDIForm1.jpg<\p>
Figure 1-1. Running an MDI form application Now if oneself crackling "Win App" and then "User Info" then both the forms perseverance open one by hallowed. These forms can live opened and dragged outside of the MDI form. This is not an expected behavior from a MDI engrossment, evenly shown in Roughhew 1-2.<\p>
This issue will come addressed succeeding in this chapter.<\p>
MDIForm2.jpg<\p>
Lords of creation 1-2. Running an MDI architecture appeal<\p>
How It Works<\p>
Each Windows Forms form is a class and exposes a Show() function abeam an as an example created for it. You use the following ethic, that is creating an object and then invoking the Fingering() technical know-how. This opens the something else again form discounting the MDI motherlike form.<\p>
This creates an symbol 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 ourselves for they:<\p>
UserInfo objUI = new UserInfo(); objUI.Show();<\p>
You strong the application by use of the following dictum:<\p>
Plaster cast.Out();<\p>










