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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#region Imports
 
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Text;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region NightHeaderLabel
 
    public class NightHeaderLabel : Label
    {
        #region Properties
 
        private PanelSide _Side;
        [Browsable(true)]
        [Description("Determines the foreground color of the label according to which side it is placed on.")]
        public PanelSide Side
        {
            get => _Side;
            set
            {
                _Side = value;
                switch (value)
                {
                    case PanelSide.LeftPanel:
                        ForeColor = _LeftSideForeColor;
                        break;
                    case PanelSide.RightPanel:
                        ForeColor = _RightSideForeColor;
                        break;
                }
                Invalidate();
            }
        }
 
        private Color _LeftSideForeColor = ColorTranslator.FromHtml("#FAFAFA");
        public Color LeftSideForeColor
        {
            get => _LeftSideForeColor;
            set
            {
                _LeftSideForeColor = value;
                Invalidate();
            }
        }
 
        private Color _RightSideForeColor = ColorTranslator.FromHtml("#AAABB0");
        public Color RightSideForeColor
        {
            get => _RightSideForeColor;
            set
            {
                _RightSideForeColor = value;
                Invalidate();
            }
        }
 
        private TextRenderingHint _TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
        [Browsable(true)]
        [Description("Specifies the quality of text rendering.")]
        public TextRenderingHint TextRenderingHint
        {
            get => _TextRenderingHint;
            set
            {
                _TextRenderingHint = value;
                Invalidate();
            }
        }
 
        #endregion
 
        #region Enum
 
        public enum PanelSide
        {
            LeftPanel,
            RightPanel
        };
 
        #endregion
 
        public NightHeaderLabel()
        {
            Font = new("Microsoft Sans Serif", 22, FontStyle.Regular, GraphicsUnit.Point);
            TextAlign = ContentAlignment.MiddleCenter;
            ForeColor = _RightSideForeColor;
            BackColor = Color.Transparent;
            UseCompatibleTextRendering = true;
        }
 
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            Focus();
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.TextRenderingHint = _TextRenderingHint;
            base.OnPaint(e);
        }
    }
 
    #endregion
}