(85) C × WinForm custom control reference block hzhcontrols

Time:2020-1-22

Official website

http://www.hzhcontrols.com

premise

It’s been 7 or 8 years since I started, I always want to make a set of beautiful custom controls, so I have this series of articles.

GitHub:https://github.com/kwwwvagaa/NetWinformControl

Code cloud: https://gitee.com/kwwwvagaa/net/winform/custom/control.git

If you think it’s OK, please click star to support it

Welcome to discuss: Penguins 568015492企鹅群568015492

Here we are. Order one[recommendation]Let’s go. Thank you

NuGet

Install-Package HZH_Controls

Catalog

https://www.cnblogs.com/bfyx/p/11364884.html

Use and effect

Preparation

There’s nothing to prepare. Just look down

start

Add a ucpanelquote class to inherit panel

Add 2 Properties

/// 
         /// The border color
         /// 
         private Color borderColor = LineColors.Light;
 
         /// 
         /// Gets or sets the color of the border.
         /// 
         /// The color of the border.
         [description ("border color"), category ("custom")]
         public Color BorderColor
         {
             get { return borderColor; }
             set
             {
                 borderColor = value;
                 this.Invalidate();
             }
         }
 
         /// 
         /// The left color
         /// 
         private Color leftColor = StatusColors.Danger;
 
         /// 
         /// Gets or sets the color of the left.
         /// 
         /// The color of the left.
         [description ("left color"), category ("custom")]
         public Color LeftColor
         {
             get { return leftColor; }
             set
             {
                 leftColor = value;
                 this.Invalidate();
             }
         }

To draw borders and colors on the left, set padding

    public UCPanelQuote()
             : base()
         {
             Padding = new Padding(5, 1, 1, 1);
         }

Repaint

 protected override void OnPaint(PaintEventArgs e)
         {
             base.OnPaint(e);
             e.Graphics.SetGDIHigh();
 
             e.Graphics.DrawLines(new Pen(borderColor), new Point[] 
             { 
                 new Point(e.ClipRectangle.Left,e.ClipRectangle.Top),
                 new Point(e.ClipRectangle.Right-1,e.ClipRectangle.Top),
                 new Point(e.ClipRectangle.Right-1,e.ClipRectangle.Bottom-1),
                 new Point(e.ClipRectangle.Left,e.ClipRectangle.Bottom-1),
                 new Point(e.ClipRectangle.Left,e.ClipRectangle.Top)
             });
 
             e.Graphics.FillRectangle(new SolidBrush(leftColor), new Rectangle(0, 0, 5, this.Height));
         }

 

Last words

If you like, please go to https://gitee.com/kwwwvagaa/net/winform/custom/control to order a star

Recommended Today

On the reference count in PHP string type

Author: Wang Shu Background introduction String type is also a commonly used type. Due to the characteristics of strings, in order to save memory, the same string variables usually share a block of memory space. By reference counting, multiple variables are marked to use this memory. However, after GDB tracking, it is found that not […]