Recognize the WinForm program and recognize the winform Program

Source: Internet
Author: User

Recognize the WinForm program and recognize the winform Program

Windows applications differ greatly from console applications.

Form1.cs: A Form file. The code written by the programmer to the form is generally stored in this file.

Form1.Designer. cs: Form Design file. The code is automatically generated by Visual Studio and generally does not need to be modified.

Form1.resx: resource file used to configure strings, images, and other resources used by the current form.

"Program. cs: Main Program file, which contains the Main () method of the Program entry

 

Partial adds a partial before the Form class. In C #, to facilitate code management and editing,

You can use the partial keyword to separate the code of the same class into multiple files. Each file is part of the class code, called the distribution class. During code compilation,

The compiler then combines and merges the code of each distribution class into a source.

 

Form is the most basic Form class defined by. NetframWork. It has some of the most basic attributes and methods of the Form. Colon represents inheritance, and all the forms we create inherit from the Form class,

Then he has the Form class, so it has the attributes and methods in the Form class. Next, let's take a look at the main attributes and methods of the Form.

Main Properties of the form
Name The name of the form object to be identified in the code.
BackColor Background Color of the form
BackgroundImage Background image of the form
FormBorderStyle Border style displayed on the form. There are 7 optional values. The default value is SizaBle.
MaximizeBox Determines whether there is a maximum box value in the upper right corner of the title bar. The default value is true.
ShowInTaskbar Determines whether the form appears in the Windows taskbar. The default value is true.
StartPosition Determine the position where the form appears for the first time
Text Text displayed in the form title bar
TopMost Indicates whether the form is always displayed on all forms whose property is not set to true. The default value is false.
WindowState Determines the initial visual status of the form, including Normal (Normal), Maximized (maximum), and Minimized (minimum). The default value is Normal.
   
Main method of Form
Close () Close form

Show ()

Display form
ShowDialog () Modular display form
Hide () Hide form

 

 

FormBorderStyle is used to set the border style of the form. If you do not want the form to run, you can drag and drop the form to change the size of the form.

Set the FormBorderStyle attribute value of the form to FixedSingle.

"Basic controls

"Label: used to display text or images that cannot be edited by the user

"Image displayed on the form

Text displayed on the form

"Text box: used to obtain user input information or text displayed to the user

"MaxLength" indicates the maximum number of characters that can be entered in the text box.

MultiLine indicates whether multiple lines of text can be entered in the text box.

"PasswordChar" indicates the characters displayed in the text box when being used as the password box, rather than the actual entered text

ReadOnly indicates whether the text in the text box can be edited.

Text associated with the Text box

"Combo box: it combines the characteristics of the text box and the list box, allows users to input text in the combo box, or select in the list

Items in the Items combo box

DropDownStyle defines the style of the combo box, indicating whether to display the list box and whether to allow users to edit the text box.

Text associated with the combo box

"SelectedIndex Index Number of the currently selected project. Each item in the list box has an index number, starting from 0

"SelectedItem

"_____ Events in the combo box:

Click single-Host Control

"SelectedIndexChanged occurs after the SelectedIndex attribute is modified

"Button: allows users to perform operations on a single machine

Boolean value of Enable, indicating whether the control is available, True indicates available, False indicates unavailable, if the control is unavailable, it is displayed as gray after running

Text displayed on the Text button

Text alignment on the TextAlign button

"_____ Events in the button

Click single-Host Control

 

TIPS: certain rules must be followed when naming controls. General rules: Abbreviations of control class names + meaningful English words.

Eg: The Button control is abbreviated as btn, so the "login" Button can be named btnLogin.

Common attributes of a control: Text, Name, and Enable. These attributes have the same meaning in different controls.

 

"MessageBox message box

In WinForm, the message box is a MessageBox object. So how to create a message box? This requires the Show () method of MessageBox.

Eg:

// Message box with title, button, and icon

MessageBox. Show (string to be displayed, message box title, message box button, and message box icon)

Knowledge: when determining an Empty string, what is the difference between string. Empty and null?

Answer: string. Empty indicates an Empty string. That is, the string object does not contain any characters, and null indicates a null reference, that is, no object is referenced.

 

"Data transmission between forms

Define a public variable Name in the Test class

public string Name;

 

"Assign value to Name in the login form (after assigning value to Name, you can call it in any class)

Test.Name = txtName.text;

"Reference the Name value in the password modification form

newName.text = Test.Name;

 

More highlights coming soon ~

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.