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
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Util;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region RoyalEllipseButton
 
    public class RoyalEllipseButton : RoyalButton
    {
        private SmoothingMode _SmoothingType = SmoothingMode.AntiAlias;
        public SmoothingMode SmoothingType
        {
            get => _SmoothingType;
            set
            {
                _SmoothingType = value;
                Invalidate();
            }
        }
 
        public RoyalEllipseButton() : base()
        {
            Size = new(120, 120);
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            Color foreColor = ForeColor;
            Color backColor = BackColor;
            //Color borderColor = BackColor;
 
            if (HotTracked && !Pressed)
            {
                backColor = HotTrackColor;
                //borderColor = backColor;
            }
            else if (Pressed)
            {
                foreColor = PressedForeColor;
                backColor = PressedColor;
                //borderColor = backColor;
            }
 
            if (DrawBorder)
            {
                //borderColor = BorderColor;
            }
 
            e.Graphics.SmoothingMode = SmoothingType;
            e.Graphics.FillEllipse(new SolidBrush(backColor), new Rectangle(2, 2, Width - (BorderThickness + 1), Height - (BorderThickness + 1)));
            e.Graphics.DrawEllipse(new(BorderColor, BorderThickness), new Rectangle(1, 1, Width - BorderThickness, Height - BorderThickness));
 
            if (Image != null)
            {
                if (LayoutFlags == RoyalLayoutFlags.ImageOnly)
                {
                    e.Graphics.DrawImage(Image, new Point((Width - Image.Width) / 2, (Height - Image.Height) / 2));
                }
            }
            else
            {
                TextRenderer.DrawText(e.Graphics, Text, Font, e.ClipRectangle, foreColor,
                    Color.Transparent, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
            }
 
            //base.OnPaint(e);
        }
    }
 
    #endregion
}