1.c# Forms and controls

Source: Internet
Author: User

1. Partial

Partial is the meaning of "partial". In C #, for easy code management and editing, you can use the Pritial keyword to separate code for the same class into multiple files. Each file is a part of the class code, also known as the distribution class, will be treated as a class by the compiler

1      Public Partial classLogin:form2     {3         //code block4     }5 6 7      Partial classLogin8     {9         //code blockTen     } One  A //two files are merged at compile time
2.form

The form is. The NET Framework defines a most basic form class that has some of the most basic properties and methods of a form, which can be obtained by (colon): Inheriting form classes to get the properties and methods of a form class defined common properties

Property Description
Name The name of the form object that is used in the code to identify
BackColor Background color of the form
BackgroundImage Background picture of a form
FormBorderStyle Form's border style, with seven optional values, default to sizable
MaximizeBox Determines if there is a maximum box in the upper-right corner of the form bar, which defaults to True
ShowInTaskbar Determines whether the form appears in the window taskbar, which defaults to True
StartPosition Determine the initial position of the form
Text The title of the form
Topmost Indicates whether the form displays on top of all forms that are not set to true on this property, false by default
WindowState

Confirm the initial visual state of the form, including normal (normal), maxximized (maximized),

Minimized (minimized) defaults to normal

These properties can be modified in the view design, and Visual Studio generates the appropriate code in the form's designer when modified

For example:

//set Form object background color This. BackColor =System.Drawing.SystemColors.Info;//set a background picture for a form This. BackgroundImage = ((System.Drawing.Image) (resources. GetObject ("$this. BackgroundImage")) ; Set the name of the form object This. Name ="Log";//set Border is not draggable This. FormBorderStyle =System.Windows.Forms.FormBorderStyle.Fixed3D;//sets whether the upper-right corner of the initial form displays a maximized box, by default True This. MaximizeBox =false;//sets whether the form appears in the window taskbar, by default True This. ShowInTaskbar =false;//set the initial position of the form This. StartPosition =System.Windows.Forms.FormStartPosition.CenterScreen;//set the initial size of the form This. WindowState = System.Windows.Forms.FormWindowState.Maximized;

Common methods for form classes

Method Property
Close () Close the form
Show () Show form
ShowDialog () Modal Display Form
Hide () Hide Form

Use of basic controls

1. Commonly used properties for tags (label)

Property Description
Image Display a picture on a label
Text The text on the label

2. Common Properties for text boxes (textbox)

            //Instantiate a text box objectTextBox TB =NewTextBox (); //maximum length that can be entered in a text boxTb. MaxLength = the; //whether multiple lines can be enteredTb. Multiline =false; //set the echo characterTb. PasswordChar ='*'; //set read-onlyTb. ReadOnly =true; //text associated with the text boxTb. Text ="This is the text of the text box";

3. Combo Box (ComboBox)

Property Description
Items Items in a combo box
DropDownStyle Define the style of the combo box
Text Text associated with a combo box
Slectedindex Occurs when a control is clicked
Slectedchanged Gets the current selected item
Event Description
Click Occurs when a control is clicked
SelectedChanged Occurs after the selected property is modified

4. Key properties and events for buttons (button)

Button Property Usage

1.c# Forms and controls

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.