tangxu
2024-12-16 23fadc9cb0c09b665a1bbcef7eaf16f916045dc4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#region Imports
 
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region Panel
 
    public class Panel : ContainerControl
    {
        private GraphicsPath Shape;
 
        private SmoothingMode _SmoothingType = SmoothingMode.HighQuality;
        public SmoothingMode SmoothingType
        {
            get => _SmoothingType;
            set
            {
                _SmoothingType = value;
                Invalidate();
            }
        }
 
        private Color _EdgeColor = Color.FromArgb(32, 41, 50);
        public Color EdgeColor
        {
            get => _EdgeColor;
            set
            {
                _EdgeColor = value;
                Invalidate();
            }
        }
 
        public Panel()
        {
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            SetStyle(ControlStyles.UserPaint, true);
 
            BackColor = Color.FromArgb(39, 51, 63);
            Size = new(187, 117);
            Padding = new Padding(5, 5, 5, 5);
            DoubleBuffered = true;
        }
 
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
 
            Shape = new();
            Shape.AddArc(0, 0, 10, 10, 180, 90);
            Shape.AddArc(Width - 11, 0, 10, 10, -90, 90);
            Shape.AddArc(Width - 11, Height - 11, 10, 10, 0, 90);
            Shape.AddArc(0, Height - 11, 10, 10, 90, 90);
            Shape.CloseAllFigures();
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
 
            G.SmoothingMode = SmoothingType;
 
            G.Clear(EdgeColor); // Set control background to transparent
            G.FillPath(new SolidBrush(BackColor), Shape); // Draw RTB background
            G.DrawPath(new(BackColor), Shape); // Draw border
 
            G.Dispose();
            e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
            B.Dispose();
        }
    }
 
    #endregion
}