2 Windows Introduction to C # Learning and host computer development

Source: Internet
Author: User

First, the Primer

The window is the open program we face a panel, inside can add a variety of controls, as shown, we can set its title name, icon, size, etc. in the property bar.

Figure 1 Window diagram 2 Setup Panel figure 3 Settings

Double-click the Caption box to generate the load function, or you can go to the event to find

The load function is the event function that needs to be executed after the window is generated.

You can add some initialization functions to the inside of it.

Second, the basic introduction

The properties and methods about him are as follows:

(key methods are highlighted in bold)

1. Common Properties   (1) Name property: Used to get or set the name of the form, which can be referenced in the application by the Name property.   (2) WindowState property: Used to get or set the window state of a form. There are three types of values: normal (the form is displayed normally), minimized (form appears minimized), and maximized (the form is displayed in maximized form).   (3) StartPosition property: Used to get or set the start position of the run-time form. The values and meanings are shown in table 9-1. The default starting position is windowsdefaultlocation. (4) Text property: This property is a string property used to set or return the text displayed in the window's title bar.   (5) Width property: Used to get or set the width of the form.   (6) Height property: Used to get or set the height of the form.   (7) Left property: Used to get or set the x-coordinate (in pixels) of the right edge of the form.   (8) Top property: Used to get or set the y-coordinate (in pixels) of the top edge of the form.   (9) ControlBox property: Used to get or set a value that indicates whether the control box is displayed in the title bar of the form. A value of true displays a control box with a value of false when the control box is not displayed.   MaximizeBox property: Used to get or set a value that indicates whether the Maximize button is displayed in the title bar of the form. A value of TRUE displays the Maximize button when the value is false and the Maximize button is not displayed.   MinimizeBox property: Used to get or set a value that indicates whether the Minimize button is displayed in the title bar of the form. A value of true displays the Minimize button when the value is false.   AcceptButton Property: This property is used to get or set a value that is the name of a button that is equivalent to clicking the button on the form when you press the Enter key.   CancelButton Property: This property is used to get or set a value that is the name of a button that is equivalent to clicking the button on the form when the ESC key is pressed.   Modal Properties: This property is used to set whether the form is a modal display form. True if the form is displayed in a modal mode, otherwise false. When a form is displayed in a modal format, only the objects on the modal form can be entered. You must hide or close the modal form (usually in response to aBefore you can enter another form. A form with a modal display is typically used as a dialog box in an application.   (ActiveControl) property: Used to get or set the active control in a container control. A form is also a container control.   (Activemdichild) property: The currently active child window used to obtain a multiple-document interface (MDI).   AutoScroll property: Used to get or set a value that indicates whether the form implements automatic scrolling. If this property value is set to True, scroll bars are displayed on the form when any control is outside the form's workspace. Also, when auto-scrolling is on, the form's workspace automatically scrolls so that the control with the input focus is visible.   BackColor properties: Used to get or set the background color of the form.   BackgroundImage property: Used to get or set the background image of the form.   Enabled property: Used to get or set a value that indicates whether the control can respond to user interaction. True if the control can be 3-  to respond to user interaction, otherwise false. The default value is true.   Font properties: The font used to get or set the text displayed by the control.   ForeColor property: Used to get or set the foreground color of the control.   Ismdichild Property: Gets a value that indicates whether the form is a multi-document interface (MDI) child form. A value of true is a subform when the value is false, not a subform.   IsMdiContainer Properties: Gets or sets a value that indicates whether the form is a container for a subform in a multiple-document interface (MDI). A value of true is a container for a subform, and a value of false when it is not a child form container.   KeyPreview property: Used to get or set a value that indicates whether the form will receive the event before the key event is passed to the control that has the focus. When the value is true, the form receives a key event and the value is false when the form does not receive the keystroke event.   (Mdichildren) Property: Array property. Each element in the array represents a multi-document interface (MDI) subform with this form as the parent.   MdiParent properties: Used to get or set the current multi-document interface (MDI) parent form for this form.   ShowInTaskbar property: Used to get or set a value that indicates whether the WindowsThe form appears in the taskbar.   Visible Property: Used to get or set a value that indicates whether the form or control is displayed. The value is true  when the form or control is displayed, False when not displayed. Capture property: If the property value is true, the mouse is qualified to respond only to this control, regardless of whether the mouse is within the scope of the control. 2. Common methods   The most common methods for some forms are described below.   (1) Show method: The function of this method is to let the form display, whose invocation format is the:  form name. Show ();  the name of the form in which the form name is to be displayed.   (2) Hide method: The function of this method is to hide the form, whose invocation format is the:  form name. Hide ();  The name of the form where the form name is to be hidden.   (3) Refresh method: The function of this method is to refresh and redraw the form, whose invocation format is the:  form name. Refresh ();  the name of the form where the form name is to be refreshed.   (4) Activate method: The function of this method is to activate the form and give it focus. Its invocation format is the:  form name. Activate ();  The name of the form in which the form name is to be activated.   (5) Close method: The function of this method is to close the form. Its invocation format is the:  form name. Close ();  the name of the form where the form name is to be closed.   (6) ShowDialog method: The function of this method is to display the form as a modal dialog box. Its invocation format is the:  form name. ShowDialog ();  3. Common events   (1) Load event: This event occurs when a form is loaded into memory, that is, before the form is first displayed.   is often used to write initialization functions (2) Activated event: This event occurs when the form is activated.   (3) Deactivate event: This event occurs when the form loses focus and becomes inactive.   (4) Resize event: This event occurs when the form size is changed.   (5) Paint Event: This event occurs when the form is redrawn.   (6) Click event: This event occurs when the user clicks the form. (7) DoubleClick Event: This event occurs when the user double-clicks the form. (8) Closed event: This event occurs when the form is closed.

Third, the application case

The event occurs when the form is closed

1. The load function is called when the main window is loaded to initialize the operation

such as the following cases:

You can initialize the maximum minimum value for the set form, and so on.

private void Form1_Load (object sender, EventArgs e)
{
This. MinimumSize = this. Size;
This. MaximumSize = this. Size;
This. MaximizeBox = false;
}

2. Create a new form

Sometimes we need a function, click on the menu and then pop up a new window.

The Name property of Window 2 is: Formdisplay

At this point we can use the following function to create

public void Btn_display_click (object sender, EventArgs e)
{
Formdisplay frmExercise1 = new Formdisplay ();//Create a new window
Frmexercise1.owner = this;
frmexercise1.closed + = new EventHandler (frm_closed);
Frmexercise1.show ();//Show This window
}

Next article: Introduction to container use

2 Windows Introduction to C # Learning and host computer development

Related Article

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.