tangxu
2024-10-16 56b9a880c8def4c0fc06f89919157fa238beeeb4
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
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Util;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region ForeverTreeView
 
    public class ForeverTreeView : TreeView
    {
        private readonly TreeNodeStates State;
 
        protected override void OnDrawNode(DrawTreeNodeEventArgs e)
        {
            try
            {
                Rectangle Bounds = new(e.Bounds.Location.X, e.Bounds.Location.Y, e.Bounds.Width, e.Bounds.Height);
                //e.Node.Nodes.Item.
                switch (State)
                {
                    case TreeNodeStates.Default:
                        e.Graphics.FillRectangle(Brushes.Red, Bounds);
                        e.Graphics.DrawString(e.Node.Text, Font, Brushes.LimeGreen, new Rectangle(Bounds.X + 2, Bounds.Y + 2, Bounds.Width, Bounds.Height), ForeverLibrary.NearSF);
                        Invalidate();
                        break;
                    case TreeNodeStates.Checked:
                        e.Graphics.FillRectangle(Brushes.Green, Bounds);
                        e.Graphics.DrawString(e.Node.Text, Font, Brushes.Black, new Rectangle(Bounds.X + 2, Bounds.Y + 2, Bounds.Width, Bounds.Height), ForeverLibrary.NearSF);
                        Invalidate();
                        break;
                    case TreeNodeStates.Selected:
                        e.Graphics.FillRectangle(Brushes.Green, Bounds);
                        e.Graphics.DrawString(e.Node.Text, Font, Brushes.Black, new Rectangle(Bounds.X + 2, Bounds.Y + 2, Bounds.Width, Bounds.Height), ForeverLibrary.NearSF);
                        Invalidate();
                        break;
                }
 
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
 
            base.OnDrawNode(e);
        }
 
        private readonly Color _BaseColor = Color.FromArgb(45, 47, 49);
        private readonly Color _LineColor = Color.FromArgb(25, 27, 29);
 
        public ForeverTreeView()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true);
 
            SetStyle(ControlStyles.UserPaint, value: false);
            SetStyle(ControlStyles.StandardClick, value: false);
            SetStyle(ControlStyles.UseTextForAccessibility, value: false);
 
            DoubleBuffered = true;
 
            BackColor = _BaseColor;
            ForeColor = Color.White;
            LineColor = _LineColor;
            DrawMode = TreeViewDrawMode.Normal;
 
            Font = new("Segoe UI", 8);
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
 
            Rectangle Base = new(0, 0, Width, Height);
 
            Graphics _with22 = G;
            _with22.SmoothingMode = SmoothingMode.HighQuality;
            _with22.PixelOffsetMode = PixelOffsetMode.HighQuality;
            _with22.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            _with22.Clear(BackColor);
 
            _with22.FillRectangle(new SolidBrush(_BaseColor), Base);
            _with22.DrawString(Text, Font, new SolidBrush(_LineColor), new Rectangle(Bounds.X + 2, Bounds.Y + 2, Bounds.Width, Bounds.Height), ForeverLibrary.NearSF);
 
            base.OnPaint(e);
 
            G.Dispose();
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.DrawImageUnscaled(B, 0, 0);
            B.Dispose();
        }
    }
 
    #endregion
}