C # WinForm Form controls panel modify border color and border width method

Source: Internet
Author: User

C # WinForm Form Control Panel modify border color and border width Method 1. Create a new component here you can customize a panel control named Panelex

2. Add a Bodercolor attribute and Bodersize property
1  PrivateColor _bordercolor =Color.Black;2 3[Browsable (true), Description ("Border Color"), Category ("Custom Grouping")]4          PublicColor bordercolor5         {6             Get{return_bordercolor;}7             Set8             {9_bordercolor =value;Ten                  This. Invalidate (); One             } A         } -  -         Private int_bordersize =1; the  -[Browsable (true), Description ("Border thickness"), Category ("Custom Grouping")] -          Public intbordersize -         { +             Get{return_bordersize;} -             Set  +             {  A_bordersize =value; at                  This. Invalidate (); -             } -}
3. Control code inherits the panel and overrides the OnPaint method
1         /// <summary>2         ///overriding the OnPaint method3         /// </summary>4         /// <param name= "E" ></param>5         protected Override voidOnPaint (PaintEventArgs e)6         {7 Controlpaint.drawborder (E.graphics,8                              This. ClientRectangle,9                              This. _bordercolor,Ten                              This. _bordersize, One Buttonborderstyle.solid, A                              This. _bordercolor, -                              This. _bordersize, - Buttonborderstyle.solid, the                             This. _bordercolor, -                              This. _bordersize, - Buttonborderstyle.solid, -                              This. _bordercolor, +                              This. _bordersize, - buttonborderstyle.solid); +}
4. Add a Test form and add a Panelex control

Compiling Run Tests

Program source code project file download

C # WinForm Form controls panel modify border color and border width method

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.