C # Basic Video Tutorial 3.1 Common types of controls and how to use them

Source: Internet
Author: User
Tags microsoft help

You can find common controls from the toolbox on the left (you want to Form1 on this form)

?

For your convenience you can also drag the entire toolbox over so that the controls are lined up from top to bottom.

?

For the button, the most common is his background color, text, font, and whether it is enabled (we enter the button name + point can access all properties of this control, events and methods, note that the property is a wrench identification, event is a lightning, method is a small square)

?

Explain the properties in detail: We first determine whether the button is enabled (this is the property of button 2, the property is like a person has his attributes, height, age, weight, name, gender, some properties are read-only, some are read-write, for control buttons, His attributes, which are all icons for wrenches, can be read and changed by his enabled property, and we can read and write his background color, text, font, size, position, and so on.

?

If I select the entire form, I can also access all the properties of the control (if it is not a visual element, but a custom class, then only the class or instance of the class + point will see all of his properties)

?

Explain the event in detail: The event is used to bind the method, that is, the button this control has a lot of events, mouse move in, mouse out, mouse down, mouse bounce (like people can have a lot of events, such as sleep, Wake up, cry, laugh, these are programmers themselves defined, We can also define the event itself when we encapsulate the controls and classes, and we can define the entire form to change the background color when the mouse presses and bounces (note the notation, as long as the + = and tab is automatically complete.) You can imagine the person three. Smile Event +=xxx method, defined in the XXX method how to do if you smile, like slap him and make him cry.

?

Why do we drag and drop a button on the form, after the click to automatically write what to do, this is also a Microsoft help us to do a step, after the click He also automatically created an event-method of the binding (in the Form1.Designer.cs file), so we can jump directly to void What to do directly in Btntest1_click's way (readers can try it out if they delete the line)

?

Explain the method in detail: We selected Form1, then we can switch to his event, directly in the Load event mouse double-click, Then write the Btntest1.performclick in the method executed by the form Load event, so that we can successfully invoke the method of the button (the default click once when initializing)

?

the method parameters of his own control are (object sender, EventArgs e) looks strange, this does not need to tube him, if the method is custom, Just use the basic data type that we talked about earlier, and you want to know what this method does, and what you output is done. Generally a function will have only one output, or no output, but there can be one or more inputs (or no input), the reader can write some methods of test run, can be proficient in writing their own methods, is to determine whether the important sign of entry, and later we encounter a practical problem, Always need to think about what methods are needed, what input each method needs, what output, the most critical function is realized, the whole project is estimated can be done, how long can be done.

?

check box checkbox and Radio box RadioButton should be put together. Because the check box can be multi-select, so it does not matter, the single box can only choose one, so to a group of radio boxes with a panel (such as gender or male or female, must choose one, can only choose one, then the gender of this group will be used a panel to wrap up, in addition to other groups, such as arts students/ Science students, different groups to separate), whether it is a single box or check box, only need to understand the check properties can read and write on the line

?

ComboBox This control is generally used to do not let the user write (to prevent the write error, want to study the use of the details of the C # three-level linkage menu, often send express when it is necessary to use the province/city of this linkage menu, do not allow users to scribble can prevent errors), the reader temporarily only need to simply delete, Add and set default items, get current content (in fact, you need to prevent the ComboBox is artificially modified value, you can Baidu or search C # FAQ to find the answer)

?

Talk about the ComboBox there is a comparison of the listbox,listbox can actually be more than the ComboBox has more properties and methods can be made, such as can be multiple selection, you can have right-click menu and so on, and then this is not explained in detail (or as long as it will add, delete, get content)

?

ScrollBars (ProgressBar) and drag bars (TrackBar) can also be put together, two are the maximum value, the minimum value, the current value (note is the integer type), the difference is that TrackBar can read and write, And ProgressBar can only see can not change (if you can not determine whether your data will exceed the maximum scroll bar minimum value, or to make a judgment to prevent illegal, otherwise the program will error)

?

PictureBox is to put an image, we'd better adjust the PictureBox to the same size as the picture (of course, you can also set the initialization of the picture, the wrong picture)

?

Notice the source of the picture, click the Resources.resx in the project, and then add the image (you can also create a new resource file with a different name, the ResX suffix is the resource file, we can easily access these images in the program after we put them in this area, or it can be other types)

?

So that we can properties.resources directly at any time. It shows all of his resources (when we import images, the names are the names of the direct numbers that may not be allowed, automatically changed to _1,_2,_3)

?

TextBox and RichTextBox can also be put together, note that the multiline of the textbox can also be directly multi-line, The advantage of RichTextBox than the traditional textbox is more suitable for processing a large number of text (the specific two controls can put how much text Baidu will know)

?

In addition RichTextBox more like Word can put pictures, hyperlink text, and textbox more like Notepad, can only put ordinary string (specific RichTextBox how to become a word or need a lot of processing, the next section will introduce others do good third-party control, Beginners do not need to spend a lot of time to study a control, especially C # programmers just drag the control on the line)

?

Label and LinkLabel are all can be implemented hyperlink (actually LinkLabel is not commonly used, because we are not doing the site, rarely need a hyperlink to where to go, do the program label with a lot of, often need to show some text, variable change situation, etc.)

?

Looking at a few more global controls, MenuStrip is the top menu bar (Visual Studio itself is a good description)

?

Corresponding to the right-click menu bar, drag and drop a contextmenustrip, and while he is displayed at the top of the form, actually run when he is hidden, You can use this right-click menu in the previous ListBox (Search menu in the toolbar to quickly navigate to these infrequently-used controls, to do the menu is to search for menus, to do the button is to search buttons)

?

In addition to the large menu bar, most of the software will also have a toolbar (in the toolbar search strip can quickly navigate to these infrequently used controls, a smaller line of text or icons, generally in the top menu bar below or the bottom of the position also put a row, so that the entire software appears to be very standard, very useful), The two correspond to ToolStrip and StatusStrip, and note their default properties in the dock (which is where the form is located, the default is top and bottom, the top and bottom, you can change to none and you can drag and drop the position arbitrarily), Of course, these complex control choreography we do not need to grasp, as long as we know that there is such a thing.

?

Finally introduced a less commonly used calendar control (choose a start time and end time, may buy a ticket, set the hotel time to use, but C # generally not used to do this), I can mouse from 9 to 12, will automatically show the start time and the end time, and calculate the number of days (for example, you want to book a hotel for a few days should be so calculated, more detailed may also be accurate to a few points, but here is simply the datatime and timespan of these C # defined time types, we still as long as it will be used on the line)

?

?

For more instructional videos and downloads, please pay attention to the following information:

My Youku Space:

Http://i.youku.com/acetaohai123

?

My online forum:

http://csrobot.gz01.bdysite.com/

?

Problem Exchange:

qq:910358960

Email:[email protected]

?

?

?

C # Basic Video Tutorial 3.1 Common types of controls and how to use them

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.