Using MDI Forms for multi-window effects

Source: Internet
Author: User

This article has been included in: C#mdi form for multi-window effects
Visual C # is Microsoft's next-generation mainstream programming language, and he is a powerful
Programming language, is being liked by more and more programmers. In Visual C #, there are many features for implementing MDI programming. This article is a concrete example of how MDI programming in Visual C # is described in detail.
A programming and operating environment:
(1) Windows 2000 Server Edition
(2). Net FrameWork SDK Beta 2
The idea, the main steps and the realization method of the second program design:
MDI programming is essentially the ability to create a new MDI form in the main form, and to cascade, tile horizontally, and tile vertically across all MDI forms in the main form. Although these operations are relatively basic, but they are the main points in the program design and focus. This article is described in the order of the above functions.
(1) First, you set the main form as a container for an MDI form, because only then can you add an MDI form on top of the main form, which allows you to program the MDI, specifically implementing the following statement:
  
 Public Form1 () {            InitializeComponent ();             true ; }

I'm just putting this on. IsMdiContainer = true; written in the form's constructor, you can also write the Form_Load function.


(2) Create a new MDI form above the main form. In the program, the command to create a new MDI form is implemented through a menu of events. In processing a new MDI form event, the key is to set the parent form of this MDI form. In fact, MDI forms and other forms are not different, the difference is that the MDI form has a first-level form, that is, the parent form, and the other forms are not, the implementation statement is as follows:
Private voidNew_click (Objectsender, EventArgs e)//This is a menu of events{Form frmtemp=NewForm (); //Create a new formfrmtemp.mdiparent= This ; //define the parent form of this form so that the form becomes an MDI formFrmtemp.text="Form 0"+formcount.tostring (); //set the title of an MDI formFormCount++ ;  Frmtemp.show (); //Show this MDI form}


(3) Implementing a cascade of MDI forms:
For the implementation of the main form of the MDI form Cascade operation, in the main program , is implemented by a method, this method is LayoutMDI, he takes the parameters are mdilayout.cascade, the implementation of the statement as follows:

Private void Object sender, EventArgs e) // implements a cascade operation {this for an MDI form in the main form   . LayoutMDI (Mdilayout.cascade);}


After implementing the operation, as follows:


Figure 01: Cascade Operations on the MDI form in the main form, click the small image to enlarge
(4) To implement horizontal tiling of MDI forms:
To implement a horizontal tiling of the MDI form in the main form, it is also through the LayoutMDI method, at which time the parameter is mdilayout.tilehorizontal, the implementation statement is as follows:
this. LayoutMDI (mdilayout.tilehorizontal);
after implementing the operation, as follows:

Figure 02: Horizontal tiling of MDI forms in the main form, click the thumbnail to enlarge
(5) To implement a vertical tile to an MDI form:
To implement the MDI form in the main form to tile vertically, also through the LayoutMDI method, at this time the parameters are mdilayout.tilevertical, the implementation of the statement as follows:
this. LayoutMDI (mdilayout.tilevertical); // to implement a vertical tile operation on an MDI form in the main form
after implementing the operation, as follows:
Figure 03: Vertical tiling of MDI forms in the main form, click the thumbnail to enlarge
(6) In some MDI programs, when a new MDI form is created, a submenu item that is named after the name of this MDI form is often produced under some menu items. To implement this functionality in other languages, you might want to add a submenu dynamically under some main menu items. However, in Visual C # to achieve this functionality, it is relatively simple, only the main menu item to be added under the following sentence to add the program can be:
Windowmenu.mdilist = true; in this program, the sub-menu items of the MDI form are added under the main menu item of the window. After adding this statement, the program runs the interface as follows:
Figure 04: Implemented in the main form after creating a new MDI form, the existing MDI Form menu item will be displayed under this main item, click the small image to enlarge
three. Program source code (Mdi.cs) and compile method:
Through the design of the difficulties introduced, it can be relatively easy to achieve the above MDI form processing of the source code (Mdi.cs), specifically as follows:
Mdi.cs source program code:
    usingSystem; usingSystem.Windows.Forms; usingSystem.ComponentModel; usingSystem.Drawing; //import namespaces used in the program    classMdidemo:form {Private Static intFormCount =1 ; //This constant is defined to count the number of MDI forms.MainMenu Mnumain =NewMainMenu ();  MenuItem Filemenu;  MenuItem Newmenu;  MenuItem Exitmenu;  MenuItem Windowmenu;  PublicMdidemo () { This. IsMdiContainer =true ;  This. Text ="MDI Demo program" ; Filemenu=NewMenuItem (); Filemenu.text="file" ; Windowmenu=NewMenuItem (); Windowmenu.text="window (&w)" ; WINDOWMENU.MENUITEMS.ADD ("form Cascade (&C)",NewEventHandler (Cascade_click)); WINDOWMENU.MENUITEMS.ADD ("horizontal tiling (&h)",NewEventHandler (Tileh_click)); WINDOWMENU.MENUITEMS.ADD ("vertical tiling (&v)",NewEventHandler (Tilev_click)); Windowmenu.mdilist=true ; //This sentence is more important, with this sentence can be achieved after you create a new MDI form, the existing MDI Form menu item is displayed under this main menu itemNewmenu =NewMenuItem (); Newmenu.text="new Form (&n)" ; Newmenu.click+=NewEventHandler (New_click); Exitmenu=NewMenuItem (); Exitmenu.text="exit (&x)" ; Exitmenu.click+=NewEventHandler (Exit_click);  FILEMENU.MENUITEMS.ADD (Newmenu); FILEMENU.MENUITEMS.ADD (NewMenuItem ("-" ) ) ;  FILEMENU.MENUITEMS.ADD (Exitmenu);  MNUMAIN.MENUITEMS.ADD (Filemenu);  MNUMAIN.MENUITEMS.ADD (Windowmenu);  This. Menu =Mnumain; }Private voidCascade_click (Objectsender, EventArgs e)//implementing cascading operations on MDI forms in the main form{ This.  LayoutMDI (Mdilayout.cascade); }Private voidTileh_click (Objectsender, EventArgs e)//implement a horizontal tile operation on an MDI form in the main form{ This.  LayoutMDI (mdilayout.tilehorizontal); }Private voidTilev_click (Objectsender, EventArgs e)//to implement a vertical tile operation on an MDI form in the main form{ This.  LayoutMDI (mdilayout.tilevertical); }Private voidNew_click (Objectsender, EventArgs e) {Form frmtemp=NewForm (); //Create a new formFrmtemp.mdiparent = This ; //define the parent form of this form so that the form becomes an MDI formFrmtemp.text ="Form 0"+formcount.tostring (); //set the title of an MDI formformcount++ ;  Frmtemp.show (); //Show this MDI form}Private voidExit_click (Objectsender, EventArgs e) { This.  Dispose ();  Application.exit (); } Public Static voidMain () {Application.Run (NewMdidemo ()); }}

After compiling the following compile command, you can get the execution program:
Csc/t:winexe/r:system.dll/r:system.windows.forms.dll/r:system.drawing.dll Mdi.cs

Four. Summary:
This article is mainly about how to use Visual C # to program MDI forms. That is, the new MDI form, the MDI form Cascade, the MDI form is horizontally tiled, and the MDI form is tiled vertically. The above introduction shows that it is fairly straightforward to work with MDI in Visual C #.
but said implementation in I do not recommend this implementation, but rather like the use of TabControl method, so easy to control, and can achieve multi-tasking, multi-action effect, is currently used by almost all the browser method

Source: http://www.sufeinet.com/thread-1364-1-1.html
Http://www.xin3721.com/ArticlePrograme/C_biancheng/1966.html

Using MDI Forms for multi-window effects

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.