diy-a custom control

Source: Internet
Author: User

    1. VS Gives us a lot of bits and pieces of control , for our use , but also because these controls are too fragmented , we want some combination of controls , with this demand, there must be this supply and demand, custom controls and user controls emerge.
  1. we've learned about user controls before,http://blog.csdn.net/tgbsqliuying/article/details/40926591
    1. difference
      1. The user control is often subordinate to an assembly, and events and properties are encapsulated inside the user control, and outside of the control is often not allowed to operate on a member of the whole. Share a large environment with the program to which it belongs.
      1. vs program use, no programming language. In contrast, a custom control is much more powerful.

  1. example of making a custom control
      1. Recommended Learning Blog: http://blog.csdn.net/smallfools/article/details/5637393 Write Super good
    1. Remember the original study C # , I learned "C # There are only classes that make up " , then C # the controls in the, naturally, are also composed of classes. The member variables of the class are: fields, properties, methods, static methods, constructors ....

So specifically to a control class, our most common is its properties and methods.

    1. In the Student Foundation project, I was confronted with the question that the display page of the announcement details is very similar to the task's display page, except that some of the details are not the same. As shown in the following:
      1. So can we encapsulate all members of the announcement task (title, Release time, task progress, the person who publishes the announcement task, the publisher of the announcement task) as a control, and all the members as properties of this control, then this control can be assigned by multiple task bulletins. The answer is of course possible.

 

    1. To learn the custom controls first:
      1. So how do you define the properties of a control?  

              

<pre name= "code" class= "CSharp" >  //Framework        private panel _pframe = new Panel ();         Frame width        private Int16 _fwidth;        [Bindable (True)]        [Category ("Data")]        [DefaultValue ("")]        [Localizable (true)]        Public Int16 fwidth        {            get {return _fwidth;}            set {_fwidth = value;}        }        Frame High        private Int16 _fheight;        [Bindable (True)]        [Category ("Data")]        [DefaultValue ("")]        [Localizable (true)]        Public Int16 fheight        {            get {return _fheight;}            set {_fheight = value;}        }        #endregion



    1. So how do you define a control's method?

The task requires editing progress, so we need to move the SelectedIndexChanged method of the Progress selection box,

<pre name= "code" class= "CSharp" >        //progress bar changed events, property access is public, so this event is a control for this user.        


We all know that the event code is not already defined in the program, we need to double-click the control when we need this event, or select event-driven, automatically generate event-driven code, and then we complement the method body, custom control, also provides, this mechanism:

<pre name= "code" class= "CSharp" >this._dpschedule.selectedindexchanged + = Neweventhandler (this._dpschedule_ SelectedIndexChanged);       Cmbox Item Change Event        private Void_dpschedule_selectedindexchanged (object sender, EventArgs e)        {            EventArgs e1 = new EventArgs ();            if (this. SelectedIndexChanged!=null) This               . SelectedIndexChanged (SelectedIndexChanged, E1);        }


because the custom control belongs to a custom control program, this program is compiled to generate DLL components, referenced in the toolbox, can be seen, used by the process, with VS comes with a control. You can try it.

diy-a custom control

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.