using ryControls; using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Windows.Forms; namespace ryControls { /// /// /// public partial class PanelEx : Panel { /// /// /// public PanelEx() { InitializeComponent(); this.BorderStyle = BorderStyle.None; } private int _radius = 10; private RoundStyle _roundeStyle; private Color _borderColor = SkinHelp.DefalutBorderColor; /// /// 控件边框颜色 /// [DefaultValue(typeof(Color), "23, 169, 254"), Description("控件边框颜色")] public Color BorderColor { get { return _borderColor; } set { _borderColor = value; base.Invalidate(); } } /// /// 控件背景颜色 /// [DefaultValue(typeof(Color), "23, 169, 254"), Description("控件背景颜色")] public Color TileBackColor { get; set; } = Color.White; /// /// 圆角弧度大小 /// [DefaultValue(typeof(int), "10"), Description("圆角弧度大小")] public int Radius { get { return _radius; } set { _radius = value; base.Invalidate(); } } /// /// 圆角风格 /// public RoundStyle RoundeStyle { get { return _roundeStyle; } set { _roundeStyle = value; base.Invalidate(); } } private void PanelEx_Paint(object sender, PaintEventArgs e) { if (this.Radius > 0) { using (Graphics g = Graphics.FromHwnd(this.Handle)) { Rectangle r = new Rectangle { Width = this.Width, Height = this.Height }; DrawBorder(g, r, this.RoundeStyle, this.Radius); } } else e.Graphics.DrawRectangle(new Pen(this.BorderColor), new Rectangle(0, 0, this.Width - 1, this.Height - 1)); } private void DrawBorder(Graphics g, Rectangle rect, RoundStyle roundStyle, int radius) { rect.Width -= 1; rect.Height -= 1; using (GraphicsPath path = Drawing.CreatePath(rect, radius, roundStyle, false)) { SolidBrush myBrush = new SolidBrush(TileBackColor); using (Pen pen = new Pen(this.BorderColor)) { g.FillPath(myBrush, path); g.DrawPath(pen, path); } } } private void PanelEx_Resize(object sender, EventArgs e) { this.Refresh(); } } }