Windows Forms Application Development 2 -- forms and controls, application development 2 --

Source: Internet
Author: User

Windows Forms Application Development 2 -- forms and controls, application development 2 --

1. Various components of Windows Forms applications

2. Main categories and functions of windows Forms controls

3. How to Handle events in Windows Forms applications

4. Add and configure Windows Forms and controls

5. Create a time processing program and monitor the program

6. add controls and Event Handlers to the form when the program is running.

 

 

1. Create a simple Windows Application

  

 

The previously created HelloWorld window can be compared with the window we usually use. There is a title bar in the upper left corner, and almost all programs in the upper right corner are minimized, maximized, and closed. Now let's look at solution explorer ). Compare several files automatically generated by the software: Assemblyinfo. cs, Resources. resx, Settings. settings, Form1.cs, Program. cs, and so on.

According to the previous code writing idea, generally the Program starts to execute from main, open Program. cs can find that there is a main function, that is, this file is the entrance to the entire project, and then open the Form1.cs file. This file is where we started to write HelloWorld. That is to say, this is a module implementing helloWorld. There is a button in this window. Click the trigger event to bring up a message. Now, if you want to add a form

 

2. Main categories and functions of windows Forms controls

We add a form named Form2.cs. Do not name this form during project creation. After adding the form, you will find that the Form1.cs form we created at the beginning is the same, and also has the form attributes. You can use the attributes to determine the functions of these forms, such as naming, or a button on the form can only be clicked on the keyboard. Common form attributes are as follows:

(Name) The name of the form in the project (similar to the ID in android when writing code). This id is used to find the visible window. The default name is the form1.cs form2.cs
AcceptButton Set a button. When you press Enter, it is equivalent to clicking this button.  
CancelButton When you press ESC, it is equivalent to clicking this button.  
ControlBox Control: Maximize, minimize, help, and close  
StrartPostion Position when the form appears for the first time  
FormBorderStyle Control the appearance of the form  
MaximizeBox Whether the maximum button exists  
MinimizeBos Minimize  
Text Text displayed on the title bar  

 

Add controls to a form

Method 1 add multiple controls to the form and adjust its size and position:

(1) toolbox

(2) double-click the control to be added in the toolbox.

(3) You can adjust the location after adding

Method 2 adjust the widget's position and size immediately after adding the widget

Method 3 Drag the control to the window

Method 1 2 3 mainly involves the use of this toolbox. You can see more with the mouse, and use the idea of "Problem driven" to see which tool is used. The toolbox is mainly used for slide.

Controls and components ):

Text editing (in the editing box, enter the account password, and write a number during accounting)

Text editing mainly includes TextBox, RichTextBox, and MaskedTestBox.

Text display (users cannot edit, text display)

Label, LinkLabel, StatusStrip

Select from List

CheckListBox displays a list of items that can be rolled. Each option has a check box.

ComboBox display drop-down list

DomainUpDown displays a text item list

..

Graphic Display

PictureBox displays graphical files, bitmaps, and icons in the framework.

Value settings

CheckBox check box and text label

Buttons and text labels that can be enabled or disabled by RadioButton

The TrackBar user moves the slider along the ruler to set the value

Content display

The number rows and series data are displayed in the Custom mesh of the DataGridView.

WebBrower allows users to browse Web pages in Forms

ProcessBar displays a proportional rectangle in the horizontal bar to indicate the operation progress.

Date settings

DateTimePicker displays a graphical calendar that allows you to select a date or time

MonthCalendar displays a graphical calendar that allows you to select a date range.

Menu Control

MenuStrip displays application commands and options grouped by function

ContexMenuStrip: When you right-click the associated control, the corresponding shortcut menu is displayed.

Command

Button provides options to start, stop, and interrupt a process

NotifyIcon displays an icon in the status notification area of the taskbar.

Container

Panel combines a group of controls on a framework without labels. you can scroll through the framework.

FlowLayout automatically arranges controls in the stream Layout

GroupBox combines a group of controls on a tag-based control. You can scroll through the control.

...

3. How to Handle events in Windows Forms applications

Event Processing: As mentioned above, a helloWorld program: click the button to bring up the message box HelloWorld

In this case, the idea is that a programmer writes this program: one click on this button triggers an event and calls a code segment to implement a function.

Create an event handler during design

(1) default event handler: Double-click a form or control to create an event handler for the default event of the object. The default event of the previous button control is click, and the form is to load an event.

(2) Properties window:

        

Locate the event in the attribute, that is, the action that triggers the event.

(3) code editor window: Create an event handler directly in the code editor. In the C # application, manually write the handler code to the window.

Create an event handler when running the program

That is, add the Code:

Button1.click + = new EventHandler (button#click );

Explanation Syntax: the object button1 calls the click. When you click a button, the new object is used. When this object is generated, the button1_click is implemented.

More event processing skills

(1) Use a single event processing method to process multiple events.

(2) create an event handling method that overrides the base class method.

 

 

Knowledge points about classes and objects:

Control Base Class: controls are inherited from the System. Windows. Forms. Control class. Generally, Widgets are components. These components combine the features of the graphic interface and pre-designed functions. In fact, controls are reusable code units used to complete specific tasks. All controls are inherited from the Control base class. Therefore, even different controls have the same attributes.

System. Object

System. deleallbyrefobject

System. ComponentModel. Component

System. Window. Forms. Control

 

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.