The 2nd chapter builds a well-laid windows

Source: Internet
Author: User

1. Use the menu bar and toolbar 1 to use the menu bar control MenuStrip

In the menu bar you can add menu items (MenuItem), combo boxes (ComboBox), text boxes (textbox),

Main properties of MenuStrip

Name: Names of menu objects in code

Items: A collection of items displayed in the menu bar

Text: Texts associated with the menu

Main properties and events of MenuItem

Name: Names of menu objects in code

DropDownItems: A collection of items displayed in a submenu

Text: Texts related to menu items

CLick (Event): This event is triggered when the menu item is selected

The steps to create the menu are as follows:

(1) switch to the form designer

(2) In the Toolbox, expand the "Menus and toolbars" tab

(3) Select MenuStrip

(4) Click the form

(5) Adding menu items

(6) Setting properties and events for menu items

The difference between application.exit () and Form.close ()

Application.exit (): The static method of the Application class application, which exits the current application. If more than one form is open for the current application, close all forms, FormClosing and fromclosed events for forms are not triggered when the form is closed

From.close (): A form class from an instance method that closes the current window if the current form is a system startup form, which executes after the method closes the form and the application exits. If the current application opens more than one form, closes the current form only, closes the form event, The formclosing and formclosed events of the form are triggered.

Settings for shortcut keys

(1) Select the menu item you want to add

(2) After the menu item text, enter & speed up the key letter

Specification:

The naming conventions for menu bars and items are as follows

When setting the Name property for a menu item, prefix MS, such as: Msuser,msadmin, etc.

When setting the Name property for a menu item, prefix Tsmi, such as tsmiaddstudentuser,tsmiexit, etc.

Experience:

Quick way to add a split bar: Click the box "Enter Here" and enter "-" in the box, which is a separate menu item

2 using the Toolbar control ToolStrip

The toolbar control can contain buttons (button), label (label), drop-down button (DropDownButton), text box (textbox), combo Box (combobox), etc., can display text, picture or text plus pictures

Main properties

Imagescalingsize: Items in the toolbar display the size of the image

Items: A collection of items that are displayed on the toolbar

Key properties and events for buttons and labels on the toolbar

Displaystyle: Set how images and text are displayed

Image: The picture displayed on the button/label

Imagescaling: Whether to adjust the size of the picture displayed on the button/label

Text: Buttons/labels displayed on

Textimagerelation: The relative position of the button/label like the text

Click: This event is triggered when a button/label is clicked

Experience:

How do I convert an added toolbar item to another form?

If you add a button to the toolbar, but later because you need to change it to a dropdown button or something else, what should I do? Select the toolbar item, right-click, choose the "Convert to" option, you will be able to convert the other forms, as needed to select the

3. Basic controls using WinForms 3.1 using the form's basic controls

radio button (RadioButton): Provides the user with a collection of options consisting of two or more mutually exclusive options

Main properties and Events

Checked: Indicates whether the radio button is selected

Text: radio button display

Click: Occurs when a radio button is clicked

Group Box (GROUPBOX): Used to provide identifiable groupings for other controls

Panel: It functions like a group box and is used to group controls. The only difference is that the panel does not have a caption, but the scroll bar can be displayed

The difference between a container control GroupBox and a panel

GRoupBox: Used to logically combine a set of controls, such as the RadioButton and CheckBox controls, to display a frame with a caption on the frame

Pannel: Used to contain multiple controls so that they can be made into a group for easy manipulation of these controls

list box (ListBox): Used to display a complete list item from which the user can select one or more options, and each element of the list is called an item

Main properties of the list box:

Items: All items in the list box

Text: The current selected item

SelectedIndex: Index number of the currently selected item

SelectItem: Gets the currently selected item

Using a control design form includes four basic steps

(1) switch to the form designer

(2) In the Toolbox, expand the All Windows Forms tab

(3) Drag the control you want to use onto the form

(4) Setting properties and events for controls

Specification:

Each control has a Name property that is used to represent the object in code. Each time we drag and drop onto a control on a form, you first need to name the control. The usual prefix: label lbl,textbox for Txt,radiobutton for Rdo,combox for CBO

3.2 Arranging controls on a form

1. Align

(1) Select the controls you want to align

(2) In the VS menu, select the "format", "Align" option, click the way you want to align

2. Using the Anchor property

Anchor is the anchoring meaning that sets the control's size to be dynamically resized with the form, as the distance between the controls and one edge of the form remains the same. Each control in WinForms has this property

The steps to anchor the control are also simple

(1) Select the control you want to anchor

(2) In the Properties window, click the Anchor property right arrow to display the Anchor property editor

(3) Select or clear the edge of the control anchor on the displayed Doji

(4) Click the Anchor property name to close the Anchor property editor

Experience:

You can always anchor multiple controls by holding down the CTRL key to select multiple controls and then setting the Anchor property

3. Use the Dock property

Use of docking

(1) Select the control you want to dock

(2) In the Properties window, click the arrow to the right of the dock property to display the dock editor

(3) Select the docking method, click "None" at the bottom to clear the docking method

(4) Click the Dock property name to close the dock editor

3.3 Creating an MDI application

1. Why use MDI

Open multiple files in the same window

2. What is MDI

MDI (multiple file interface)

3. How to create an MDI

(1) Set the parent form to set the parent form's IsMdiContainer property to True

(2) Setting up a subform: Set the MdiParent property of the subform to this in code before calling the show () method of the subform to open it

4. Combo Box combobox Control

Common Properties and methods

Count: Gets the number of items in the collection

IsReadOnly gets a value that indicates the ability to modify the collection

Item: Retrieves the item from the specified index in the collection

Method:

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

Clear (): Remove all items from the combo box

Remove (): Removes the specified item from the combo box

The 2nd chapter builds a well-laid windows

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.