C # Custom Control Properties panel and select resource Settings

Source: Internet
Author: User

Because you want to do a fluid layout, but two controls can't be combined, do a custom control. This control requires a text setting, a PIC settings image display, and a picture that can be modified in the Properties panel by selection.

After adding a user control, you can set the contents of the control at your own discretion, and here are some settings for properties.

  1. The custom control displays the switch in the Toolbox:
    Change true to False to not display.

    [ToolboxItem (true)]  Public Partial class Usercontrol1:usercontrol

  2. The icon for the custom control in the Toolbox is displayed:
    You can use an icon for an existing control,
    1 [ToolboxBitmap (typeof(System.Windows.Forms.PictureBox))]2 Public Partial class Usercontrol1:usercontrol

    If you do not want to use the system's icon, you want to work with your own icon, you can (this part is not tested, from the reference article)

    1 [ToolboxBitmap (typeof"WindowsApplication1.Images.MyPanel.bmp"  )]2publicclass Mypanel:usercontrol

    However, be sure to note the path, WindowsApplication1.Images.MyPanel.bmp says the solution is WindowsApplication1, the directory is Images, the file name is Mypanel.bmp, and the image must be "embedded resources" (Click File, right, property, have a file attribute, where, in the build operation, you can select "Embedded Resource")


  3. Custom Controls display switches on the properties panel:
    1[Browsable (true)]2[Description ("Property Description"), Category (the property name"), DefaultValue ("property default value, reset using")]3  Public Override stringText4         {5             Get{returnLabel1. Text; }6             Set{Label1. Text =value;}7}

    (Excerpt from the reference article) is used to set the default value, for String,bool,int, can be written directly, such as [DefaultValue (10)], this is OK, but, not the three types, it is more troublesome, must first be converted to a string to set the success. As Darkgray above, this is a system-defined color, which is better handled. However, if it is some custom color, such as color is 128, 0,128, you should convert 128 to 16, written as 0x800080, prefix 0x is bound to add. Finally, [DefaultValue (typeof (Color), "0x800080")]
    There is also a [DefaultValue (typeof (Color), "0, 70, 213")]
    If the font is required [DefaultValue (typeof (Font), "Arial, 9pt")]
    Neither of these special cases has been tested by either of the three methods.

  4. To select a resource for a custom control property:
    If the custom attribute is not input such as text, it is necessary to select a resource similar to PictureBox, so the file type is used when setting the attribute, such as the example of selecting a picture
    1[Browsable (true)]2[Description ("To set a picture of a control"), Category ("Setpic"), DefaultValue (" ")]3  PublicBitmap setpic4         {5             Get{return(Bitmap) This. pictureBox1.Image;}6             Set7             {8                 This. pictureBox1.Image =value;9             }Ten}

    This will be selected by selecting a Resource dialog box in the settings of the Properties panel.

  5. Custom control Property Selection drop-down list:

    When defining a property, you need to set the enumeration value to define the attribute by enumerating, as in the example

    1 public enum        {                                       } 7 public Indexenum index; 8 [browsable (True )] 9 [Description ("Set Index"), Category ("index"), defaultvalue ("attribute default")]10 public {get {return } Index }13 set {index = value;} +}          

Report:

Reference article: Common design Properties "C #" Mom no longer have to worry about how custom controls add default values to special types of properties, with a custom GroupBox

C # Custom Control Properties panel and select resource Settings

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.