C # Basic Video tutorial 3.3 Common types of controls and how to use them

Source: Internet
Author: User

The Microsoft controls described earlier, as well as several third-party controls, how are these controls made? Even if we do not do the controls ourselves, we must at least understand the principle of the control.

If you are creating a custom control, first create a new Windows Forms Control Library under C #

?

The simplest method is simply to drag a label, put a timer, the timer gets and displays the current system time every second (F5 can run the test to see the effect)

?

So, just like before, drag and drop this generated DLL into the toolbox to use the new project.

?

Slightly more complicated, we also rewrite the official RichTextBox so that he can insert images and import RTF files. The first is to create a new custom control UserControl2, notice that he inherits from UserControl by default, we change to inherit from RichTextBox

?

Add two additional features for this control (you can see all 0 references, all 0 references that are not used in the current program), the specific import of RTF, insert the picture why this can be, in fact, you have been using RichTextBox when you have realized these features, But now you have the original RichTextBox and some common functions, so that the control is better to use (we are not really starting from scratch to write a control, but just a little bit to improve the original control, so we are still using the original space of the LoadFile, Controls.Add these methods)

?

Note that this custom control does not need to UserControl any of the properties and methods, so in initializecomponet when the original definition of properties and methods are removed clean (if you switch to Design view, only see the following sentence, this is normal, Because inheriting from UserControl is a picture, the custom class does not, or unless you add it yourself)

?

After that, click Build, rebuild the solution, and get the new DLL (if F5 run an error, do not control it)

?

After the control has these two methods, it can be generated, dragged and dropped into the new project, and then at any time the button click can execute the control's own import method, very efficient

?

You can import images, including GIF

?

You can also import the entire document (RTF format)

?

Summary: This section of the course content, but actually do not need to grasp immediately, the real use of the time to think how to use, so long as the understanding can, even if the program, the reader needs to do their own testing:

1 Microsoft comes with a variety of controls for functional testing, to understand common property methods, especially basic Label,button,textbox these controls, will be used in the future

2 simple use of third-party controls to learn about the additional properties and methods of third-party controls compared to Microsoft's own controls (if you need to be able to quickly use third-party controls to beautify the interface)

3 Simple writing of third-party controls to understand how third-party controls are designed

?

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.3 Common types of controls and how to use them

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.