|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis article will demonstrate an easy and effective way to include MDI support in your Windows Forms Applications (.NET)! There are many examples on MSDN, but none of them puts together a sample program that is all in one place. Adding MDI support to your application gives you the advantage of managing multiple files or some other form of data with one template. This will dramatically reduce the amount of coding that you have to do, and will allow end users the comfort of working with an application that gives them the power to work with tons of data all at once. This article will show you how to setup a basic application with MDI support that uses a Using the codeIn the source zip, you will find this entire project with all the steps completed below. First of all, this article is written mainly for Microsoft Visual C++ .NET 2003 users. There is no guarantee that this code will work with previous or future versions! Let's start off by opening a blank Microsoft Forms Application (.NET) and naming it MDIApp.
Click OK, and you will be presented with a blank form named Next, click the form and open the Properties window. Under
Now that we have our MDI container, we need to add a menu. Drag a Now that we have our parent window, it's time to create a child window. In the Solution Explorer, right-click the project, point to Add, and then select Add New Item. In the Add New Item dialog box, select Windows Forms Application (.NET) from the Templates pane. In the Name box, name the form Form2 (again, if you change this, you will have to substitute). Click the Open button to add the form to the project. Drag a Add the following code under our new function that was created: private: System::Void menuItem2_Click(System::Object * sender,
System::EventArgs * e)
{
// This gets a new instance of our child window.
Form2* newMDIChild = new Form2();
// Tells our new child window
// what is our parent window.
newMDIChild->MdiParent = this;
// Shows the new form.
// Don't confuse this with ShowDialog!
newMDIChild->Show();
}
That will create a new child window with the design that we made. Scroll to the top and add the line below... #include "Form2.h"
Go back to our design view and create a click event handler for the Exit menu item. Add the following code under our new function that was created for the Exit menu item: private: System::Void menuItem3_Click(System::Object * sender,
System::EventArgs * e)
{
this->Close(); // Closes the application!
}
Press F5 to run the application. Note that by selecting New from the File menu, you can create new MDI child forms, which are kept track of in the Window menu. Points of InterestBefore I learned about MDI for .NET, I was forced to use Microsoft's alternative method in making my program MFC. This wasn't useful for me because I am new to MFC and don't know many functions. Also, it is useful to add XP support so that people with XP will see a cleaner design. It will also help to add a status bar to fill the missing space at the bottom of the window. The last thing is something in my preference but it is recommended that you set your child window to HistorySo far this is the first article and first version of this article that I have made! ;-)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||