How to build a good windows program (required for beginners)

Source: Internet
Author: User

How to build a good windows program (required for beginners)

1. Use the menu bar and toolbar

1. What are the functions and advantages of the menu bar and toolbar:

You can use the menu bar to group the functions of an application, so that you can easily find and use them. Each item in the menu bar shown is a top-level menu item, the options under the top menu item are called "sub menu" or "menu item ";

By listing common functions in the toolbar, you do not need to go to the menu bar to find the corresponding functions. You can directly select the functions in the toolbar.

2. Use the menu bar control MenuStrip

01. You can only add menu items (MenuItem), ComboBox, and TextBox to the menu bar)

02. main attributes of the menu bar

Name: Name of the menu object in the code.

Items: a set of Items displayed in the menu.

Text: The Text associated with the menu item.

03. in the Items attribute editing window, you can add MenuItem, ComboBox, TextBox, and Separator ), you can also set the attributes of each item and adjust the order of each item.

04. Main Properties and events of menu items:

Attribute:

Name: Name of the menu item object in the code.

DropDownItems: the set of items displayed in the sub-menu.

Text: The Text associated with the menu item.

Event:

Click: this event is triggered when this menu item is selected.

05. Shortcut Keys on the menu bar:

Method 1: Find the Text property in the menu bar: write new (& A) write the project (& B) file (& C) in the menu item, this will achieve this effect

Open Mode: First, you must press the alt + Main Menu shortcut to enter the corresponding main menu, and then press F to open the subform.

Disadvantage: you must first use alt + characters, first locate the level-1 menu, and then press B key C to locate the corresponding content

Method 2:

Open the property, find shortCutKeys, and create a key combination. You can directly press the secret key on the main interface to open the subform. If you set the shortcut key (Ctrl + B ). Press Ctrl + B to open the project.

Open. Advantage: you can skip the level 1 menu and directly call the required window and split line.

06 description of the split line:

<1> insert a split line

<2> enter the minus sign (-)

3. Differences between Application. Exit () and this. Close ()

Application. Exit () This. Close ()
Static Method of the Application class Application, used to exit the current Application.

Instance method, used to close the current form; if the current form is started by the System

To close the form, and the application exits.

If the current application opens multiple forms, close all forms If the current application opens multiple forms, only the current form is closed.
When the form is closed, the FormClosing and FormClosed events of the form are not triggered. When the form is closed, the FormClosing and FormClosed events of the form are triggered.

4. Use the Toolbar Control ToolStrip

01. Note: only controls in the preceding figure are included in the toolbar.

02. main attributes of the Toolbar Control:

ImagesScalingSize: the size of the image displayed by the item in the toolbar.

 

Items: a set of Items displayed on the toolbar.

Note: In the Itens attribute editing window, you can add or delete items, adjust the order of items, and set attributes for each item.

03. main attributes and events of buttons and labels on the toolbar.

Attribute:

DisplayStyle: sets the display mode of the image and text, including text, image, text, image, or nothing.

Image: The Image displayed on the button/Tag

ImageScaling: whether to adjust the size of the image displayed on the button/Tag

Text: Text displayed on buttons/labels

TextImageRelation: the relative position of the button/Tag image and text.

Event:

Click: Click the button/tag to trigger the event.

04. about setting the image size in the toolbar:

Select the entire ToolsStrip control and find the ImageScalingSize attribute. You can set the width and height.

2. Use Basic WinForms controls

1. Single-choice button: (RadioButton)

Provides a set of options consisting of two or more mutex options.

Main attributes and events of Single-choice buttons:

Attribute:

Checked: indicates whether the single-choice button is selected.

Text: The Text displayed by the radio button.

Event:

Click: A single-host single-choice button occurs.

2. Group box: (GroupBox)

It is used to provide identifiable groups for other controls. Generally, the grouping box is used to subscribe the form by function.

3. Panel: (Panel)

Its function is similar to the grouping box, which is used to group controls. The only difference is that the Panel does not have a title, but the scroll bar can be displayed.

4. Differences between container controls GroupBox and Panel:

GroupBox) Panel)

Controls used to combine logic, such as RadioButton and CheckBox controls,

Displays a framework with a title.

It is used to contain multiple controls, so that these controls can be grouped into a group for easy operation.

5. Date control.

A drop-down calendar that can be used to select a date is provided to avoid unnecessary troubles caused by manual input.

Main Properties of the date control:

MaxDate: Get the set maximum date and time.

MinDate: Get the set minimum date and time.

Value: the date/time Value selected by the control.

Format: used to set the Format of the date and time displayed in the control.

6. Use the Anchor and Dock attributes:

<1> Anchor attribute: Anchor is an Anchor attribute. It is used to set the distance between the control and an edge of the form to remain unchanged, so as to dynamically adjust the widget size as the form changes. each control in Winform has this attribute.

Steps for anchoring a control:

01. Select the control to be anchored

02. In the "properties" window, click the drop-down button on the right of the Anchor attribute to display the Anchor Attribute Editor.

03. Select or clear the side anchored by the control on the displayed cross star.

04. Click the Anchor attribute name to close the Anchor Attribute Editor.

<2> use the Dock attribute:

01. Select the control to be docked.

02. In the "properties" window, click the drop-down button on the right of the Dock property to display the Dock editor.

03. Select the dock mode and click "None" at the bottom to clear the dock mode.

04. Click the Dock property name to close the Dock editor.

Summary of Anchor and Dock attributes:

Anchor: keeps the control and the edge of the form at a fixed pixel value.

Dock: place the control in a certain part of the form (Top, Bottom, Left, RIght), or Fill the entire form (Fill)

Create an MDI application:

1. Create an MDI:

01. Set the parent form: Set the IsMdiContainer attribute of the parent form to True.

02. Set the subform: Before calling the Show () method to open the subform, set the MdiParent attribute of the subform to this in the code.

4. ComboBox control.

Items is the attribute of the combo box. It represents the set of Items in the combo box. The Items attribute is used for operations on Items in the combo box. Its type is ComboBox. ObjectCollection.

Common attributes and methods of the ComboBox. ObjectCollection type

Attribute:

Count: obtains the number of items in the set.

DropDownStyle: gets or sets the value of the specified combo box style.

IsReadOnly: gets the value indicating that the set can be modified.

Item: the Item of the specified index in the search set.

Method:

Add (): Add an item to the items list of the combo box.

Clear (): removes all items from the combo box.

Remove (): removes the specified item from the combo box.

 

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.