• 圆角Panel


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing.Drawing2D;
    using System.Drawing;
    
    namespace POS.Controls
    {
        public partial class PosPanel : Panel
        {
            public PosPanel()
            {
                InitializeComponent();
            }
    
            private int mMatrixRound = 8;
            private Color mBack;
    
            public Color Back
            {
                get { return mBack; }
                set
                {
                    if (value == null)
                    {
                        mBack = Control.DefaultBackColor;
                    }
                    else
                    {
                        mBack = value;
                    }
                    base.Refresh();
                }
            }
    
            public int MatrixRound
            {
                get { return mMatrixRound; }
                set
                {
                    mMatrixRound = value;
                    base.Refresh();
                }
            } 
    
            private GraphicsPath CreateRound(Rectangle rect, int radius)
            {
                GraphicsPath roundRect = new GraphicsPath();
                //顶端 
                roundRect.AddLine(rect.Left + radius - 1, rect.Top - 1, rect.Right - radius, rect.Top - 1);
                //右上角 
                roundRect.AddArc(rect.Right - radius, rect.Top - 1, radius, radius, 270, 90);
                //右边 
                roundRect.AddLine(rect.Right, rect.Top + radius, rect.Right, rect.Bottom - radius);
                //右下角
    
                roundRect.AddArc(rect.Right - radius, rect.Bottom - radius, radius, radius, 0, 90);
                //底边 
                roundRect.AddLine(rect.Right - radius, rect.Bottom, rect.Left + radius, rect.Bottom);
                //左下角 
                roundRect.AddArc(rect.Left - 1, rect.Bottom - radius, radius, radius, 90, 90);
                //左边 
                roundRect.AddLine(rect.Left - 1, rect.Top + radius, rect.Left - 1, rect.Bottom - radius);
                //左上角 
                roundRect.AddArc(rect.Left - 1, rect.Top - 1, radius, radius, 180, 90);
                return roundRect;
            }
    
            protected override void OnPaint(PaintEventArgs e)
            {
                int width = base.Width - base.Margin.Left - base.Margin.Right;
                int height = base.Height - base.Margin.Top - base.Margin.Bottom;
                Rectangle rec = new Rectangle(base.Margin.Left, base.Margin.Top, width, height);
                GraphicsPath round = CreateRound(rec, mMatrixRound);
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                e.Graphics.FillPath((Brush)(new SolidBrush(mBack)), round);
            } 
        }
    }

    使用的时候背景颜色设为透明,Back是前景色,设一个不同的颜色。就OK了

  • 相关阅读:
    int.Parse()及其异常判断
    三个框框的EditBox
    等价类的划分方法与EditorBox问题等价类划分
    初学软件测试
    软件测试方法的分类细谈
    浅谈软件测试之回归测试
    白盒测试——基本路径法
    初探灰盒测试——介于白盒测试与黑盒测试的测试
    对闰年测试的非法输入处理的思考
    等价类测试——进一步完善的Web输入合法验证
  • 原文地址:https://www.cnblogs.com/wpcnblog/p/5016219.html
Copyright © 2020-2023  润新知