Multi-document interface processing (MDI)

Source: Internet
Author: User
From: http://qianshao.blog.51cto.com/935360/201520

UObjective of this section:

N understand the concepts and differences between MDI and SDI

N proficient in setting the primary attributes of the MDI form and General Form

N skills in the arrangement of MDI forms

N The form value passing technology that masters and implements Multi-document interfaces

1-4-1 Introduction

The window we designed previously is called the single document window (SDI), as shown in 1-18. However, in many cases, the application software is developed and designed in a multi-document window environment. This multi-document interface is called MDI, which is a Microsoft Excel spreadsheet under Windows 2.0.ProgramThis was introduced at the beginning because Excel spreadsheet users sometimes need to operate multiple tables at the same time, and MDI is a great convenience for such operations on multiple tables, so an MDI program is generated. In Windows 3.1, MDI has been widely used. The program manager and file manager in the system are both MDI programs.

Figure 1-18 general single document (SDI) Interface

MDI programming is mainly to create an MDI form in the main form, and to cascade, horizontally tile, and vertically tile all the MDI forms in the main form. Although these operations are basic, they are the key points and key points in programming.

1-4-2 Multi-document interface settings and form attributes 1. Multi-Document Interface (MDI) attribute description

Generally, the generated forms belong to a single document form (SDI). Only when the ismdicontainer attribute of a single document form is set to true can it be set to a multi-document form. See Figure 1-19.

Figure 1-19 changed from single document (SDI) to multi-document (MDI) Interface

The basic attribute of the Multi-document interface is actually the form attribute. The main attributes, methods, and events of the form are shown in Table 1-7:

Attribute

Description

Startposition

The initial window position. Generally, this attribute value is set to centerscreen to align the center when the form is started.

Cancelbutton

This attribute allows you to automatically search for all button objects in the current form. You can click esc to execute the button in the list.

Controlbox

Determine whether the system has the icon and the max/min close button. The attribute values are true and false. If the attribute value is false, the title column icon and the max. Min close button cannot be seen.

Formborderstyle

Specifies the appearance and behavior of the border and title bar. There are a total of seven effects to choose from. For example, when fixedtoolwindow is selected, only the close button exists, and no maximum or minimum button exists.

Helpbutton

Determine whether there is a help button on the title bar of the form.

Keypreview

Determine whether the form keyboard event has been registered with the form.

Mainmenustrip

Confirm keyboard activation and multi-document merge.

Showintaskbar

Determine whether the form is displayed in the taskbar.

Windowstate

Determine the initial visual status of the form. There are three statuses: normal is normal, maximized is the initial maximization, and minimized is the initial minimization.

Method

Description

Activate

This occurs when the form is activated.

Mdichildactivate

This occurs when the MDI subform is activated.

Event

Description

Activated

This occurs whenever the form is activated.

Load

Every time a user loads a form

Table 1-7 MessageBox. Show () method overload

Please try the properties and effects of the form Attributes Based on the prompts.

2. Case study: Create a multi-Document Interface (MDI)

The purpose of this experiment is to first create a form main form, create a menu in the main form, and open the remaining child forms through the menu. The page is displayed from 1 to 17.

Figure 1-20 main document interfaces

U lab step (1 ):

As shown in figure 1-18, first set the Form attribute of the current operation as follows:

Attribute name

Attribute parameter settings

Description

Text

Parent window

Form Tag Name

Startposition

Centerscreen

Center form

Formborderstyle

Fixedtoolwindow

No Max & min buttons

Ismdicontainer

True

Set as MDI Main Window

U lab step (2 ):

Configure the mainmenu for this MDI form. The Toolbox does not have this control by default. Open All Windows controls of the toolbox, right-click the Toolbox interface, and select "select item" from the menu that appears ", search for the mainmenu control in the expanded system selection item. After adding the control, it appears in the Windows Control Section. Operations 1-21 are as follows:

Figure 1-21 Add a mainmenu control to the MDI form

U lab step (3 ):

Open solution Resource Manager and create a new windows form named form2. This form is not an MDI form, that is, you do not need to specify its ismdicontainer attribute as true. Double-click subwindow 1 in the menu item in Figure 1-20 to enterCodeIn the editing area, enter the following code:

Lab:Subwindow 1 menu item mouse click eventSource code:

Private void menuitem3_click (Object sender, eventargs E)

{

Form2 mdichild = new form2 (); // first instantiate the form2 object and name it mdichild

Mdichild. mdiparent = this;

// Specify the mdiparent of the forthcoming form2 object, that is, the MDI parent window of the form2 object, which is the current primary MDI window.

Mdichild. Show (); // display the MDI parent window of the form2 object

}

In this case, the open form2 form can only be active under the current form, without the range of the current form. Follow these steps to create two forms named form3 and form4. You can click subwindow 2 and subwindow 3 to open them.

3. Case study: arrange the MDI forms

(1) cascade the MDI form

For the cascade operation on the MDI form in the main form, the layoutmdi method is used in the main program. The parameter it carries is mdilayout. cascade: Add the following code to the original menuitem3_click event:

Lab:Source code of the MDI form:

Private void menuitem3_click (Object sender, eventargs E)

{

.......

This. layoutmdi (mdilayout. Cascade );

}

(2) Horizontal Tile of the MDI form

To horizontally tile the MDI form in the main form, the layoutmdi method is also used. The parameter is mdilayout. tilehorizontal. Modify the following code in the original menuitem3_click event:

Lab:Horizontal tiled source code of the MDI form:

Private void menuitem3_click (Object sender, eventargs E)

{

......

This. layoutmdi (mdilayout. tilehorizontal );

}

(3) Implement vertical Tile of the MDI form

To vertically tile the MDI form in the main form, the layoutmdi method is also used. The parameter is mdilayout. tilevertical. Modify the following code in the original menuitem3_click event:

Lab:Vertical tile source code of the MDI form:

Private void menuitem3_click (Object sender, eventargs E)

{......

This. layoutmdi (mdilayout. tilevertical );

}

The above experiment results are shown in Figure 1-22:

Figure 1-22 multiple ways to arrange child forms in an MDI form

This article is from the "pandatv writing program" blog. For more information, contact the author!

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.