tangxu
2024-10-23 6a9aa8b628ace581657972a2e502ceb9a58b2395
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Colors;
using DPumpHydr.WinFrmUI.RLT.Util;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region ForeverStatusBar
 
    public class ForeverStatusBar : Control
    {
        private int W;
        private int H;
 
        protected override void CreateHandle()
        {
            base.CreateHandle();
            Dock = DockStyle.Bottom;
        }
 
        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);
            Invalidate();
        }
 
        [Category("Colors")]
        public Color BaseColor { get; set; } = Color.FromArgb(45, 47, 49);
 
        [Category("Colors")]
        public Color TextColor { get; set; } = Color.White;
 
        [Category("Colors")]
        public Color TimeColor { get; set; } = Color.White;
 
        [Category("Colors")]
        public Color RectColor { get; set; } = ForeverLibrary.ForeverColor;
 
        [Category("Options")]
        public bool ShowTimeDate { get; set; } = false;
 
        [Category("Options")]
        public string TimeFormat { get; set; } = "dd.MM.yyyy - HH:mm:ss";
 
        [Category("Options")]
        public string TimeFormatDefault => "dd.MM.yyyy - HH:mm:ss";
 
        public string GetTimeFormat(string TF)
        {
            try
            {
                return DateTime.Now.ToString(TF);
            }
            catch
            {
                TimeFormat = TimeFormatDefault;
                TimeFormat = TimeFormatDefault;
                return DateTime.Now.ToString(TimeFormatDefault);
            }
        }
 
        public ForeverStatusBar()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true);
            DoubleBuffered = true;
            Font = new("Segoe UI", 8);
            ForeColor = Color.White;
            TimeFormat = TimeFormat;
            Size = new(Width, 20);
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            //UpdateColors();
 
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
            W = Width;
            H = Height;
 
            Rectangle Base = new(0, 0, W, H);
 
            Graphics _with21 = G;
            _with21.SmoothingMode = SmoothingMode.HighQuality;
            _with21.PixelOffsetMode = PixelOffsetMode.HighQuality;
            _with21.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            _with21.Clear(BaseColor);
 
            //-- Base
            _with21.FillRectangle(new SolidBrush(BaseColor), Base);
 
            //-- Text
            _with21.DrawString(Text, Font, new SolidBrush(TextColor), new Rectangle(10, 4, W, H), ForeverLibrary.NearSF);
 
            //-- Rectangle
            _with21.FillRectangle(new SolidBrush(RectColor), new Rectangle(4, 4, 4, 14));
 
            //-- TimeDate
            if (ShowTimeDate)
            {
                string Time = GetTimeFormat(TimeFormat);
                _with21.DrawString(Time, Font, new SolidBrush(TimeColor), new Rectangle(-4, 2, W, H), new StringFormat
                {
                    Alignment = StringAlignment.Far,
                    LineAlignment = StringAlignment.Center
                });
            }
 
            base.OnPaint(e);
            G.Dispose();
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.DrawImageUnscaled(B, 0, 0);
            B.Dispose();
        }
 
        private void UpdateColors()
        {
            ForeverColors Colors = ForeverLibrary.GetColors(this);
 
            RectColor = Colors.Forever;
        }
    }
 
    #endregion
}