yangyin
2025-03-27 b0de14c2670b9ff0079dacfb4b7457b438368f11
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Extension;
using DPumpHydr.WinFrmUI.RLT.Util;
using System;
using System.Drawing;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region LostCheckBox
 
    public class LostCheckBox : ControlLostBase
    {
        public event EventHandler CheckedChanged;
        private bool _checked = false;
        private Color _checkedcolor = ThemeLost.FontBrush.Color;
        public bool Checked
        {
            get => _checked;
            set
            {
                _checked = value;
                Invalidate();
                CheckedChanged?.Invoke(this, null);
            }
        }
        public Color CheckedColor
        {
            get => _checkedcolor;
            set
            {
                _checkedcolor = value;
                Invalidate();
            }
        }
 
        public LostCheckBox() : base()
        {
            Font = ThemeLost.BodyFont;
            ForeColor = Color.White;
            Cursor = Cursors.Hand;
        }
 
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            pevent.Graphics.FillRectangle(MouseOver ? new SolidBrush(ThemeLost.ForeColor.Shade(ThemeLost.ShadowSize, 0)) : new SolidBrush(BackColor), ClientRectangle);
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            if (MouseOver)
            {
                e.Graphics.FillRectangle(new SolidBrush(ThemeLost.ForeColor.Shade(ThemeLost.ShadowSize, 0)), ClientRectangle);
            }
 
            e.Graphics.DrawRectangle(ThemeLost.FontPen, 1, 1, Height - 2, Height - 2);
 
            if (Checked)
            {
                e.Graphics.FillRectangle(new SolidBrush(_checkedcolor), 4, 4, Height - 7, Height - 7);
            }
 
            SizeF textSize = e.Graphics.MeasureString(Text, Font);
            e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), Height + 3, (Height / 2) - (textSize.Height / 2));
        }
 
 
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            Checked = !Checked;
            Invalidate();
        }
 
        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);
            HasShadow = true;
            Parent.Invalidate(ShadeRect(ThemeLost.ShadowSize), false);
            Invalidate();
        }
 
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            HasShadow = false;
            Parent.Invalidate(ShadeRect(ThemeLost.ShadowSize), false);
            Invalidate();
        }
    }
 
    #endregion
}