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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Drawing.Poison;
using DPumpHydr.WinFrmUI.RLT.Enum.Poison;
using DPumpHydr.WinFrmUI.RLT.Extension.Poison;
using DPumpHydr.WinFrmUI.RLT.Interface.Poison;
using DPumpHydr.WinFrmUI.RLT.Manager;
using DPumpHydr.WinFrmUI.RLT.Util;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region PoisonToolTip
 
    [ToolboxBitmap(typeof(ToolTip))]
    public class PoisonToolTip : ToolTip, IPoisonComponent
    {
        #region Interface
 
        private ColorStyle PoisonStyle = ColorStyle.Blue;
        [Category(PoisonDefaults.PropertyCategory.Appearance)]
        public ColorStyle Style
        {
            get
            {
                if (StyleManager != null)
                {
                    return StyleManager.Style;
                }
 
                return PoisonStyle;
            }
            set => PoisonStyle = value;
        }
 
        private ThemeStyle PoisonTheme = ThemeStyle.Light;
        [Category(PoisonDefaults.PropertyCategory.Appearance)]
        public ThemeStyle Theme
        {
            get
            {
                if (StyleManager != null)
                {
                    return StyleManager.Theme;
                }
 
                return PoisonTheme;
            }
            set => PoisonTheme = value;
        }
 
        [Browsable(false)]
        public PoisonStyleManager StyleManager { get; set; } = null;
 
        #endregion
 
        #region Fields
 
        [DefaultValue(true)]
        [Browsable(false)]
        public new bool ShowAlways
        {
            get => base.ShowAlways;
            set => base.ShowAlways = true;
        }
 
        [DefaultValue(true)]
        [Browsable(false)]
        public new bool OwnerDraw
        {
            get => base.OwnerDraw;
            set => base.OwnerDraw = true;
        }
 
        [Browsable(false)]
        public new bool IsBalloon
        {
            get => base.IsBalloon;
            set => base.IsBalloon = false;
        }
 
        [Browsable(false)]
        public new Color BackColor
        {
            get => base.BackColor;
            set => base.BackColor = value;
        }
 
        [Browsable(false)]
        public new Color ForeColor
        {
            get => base.ForeColor;
            set => base.ForeColor = value;
        }
 
        [Browsable(false)]
        public new string ToolTipTitle
        {
            get => base.ToolTipTitle;
            set => base.ToolTipTitle = "";
        }
 
        [Browsable(false)]
        public new ToolTipIcon ToolTipIcon
        {
            get => base.ToolTipIcon;
            set => base.ToolTipIcon = ToolTipIcon.None;
        }
 
        #endregion
 
        #region Constructor
 
        public PoisonToolTip()
        {
            OwnerDraw = true;
            ShowAlways = true;
 
            Draw += new DrawToolTipEventHandler(PoisonToolTip_Draw);
            Popup += new PopupEventHandler(PoisonToolTip_Popup);
        }
 
        #endregion
 
        #region Management Methods
 
        public new void SetToolTip(Control control, string caption)
        {
            base.SetToolTip(control, caption);
 
            if (control is IPoisonControl)
            {
                foreach (Control c in control.Controls)
                {
                    SetToolTip(c, caption);
                }
            }
        }
 
        private void PoisonToolTip_Popup(object sender, PopupEventArgs e)
        {
            if (e.AssociatedWindow is IPoisonForm form)
            {
                Style = form.Style;
                Theme = form.Theme;
                StyleManager = form.StyleManager;
            }
            else if (e.AssociatedControl is IPoisonControl control)
            {
                Style = control.Style;
                Theme = control.Theme;
                StyleManager = control.StyleManager;
            }
 
            e.ToolTipSize = new(e.ToolTipSize.Width + 24, e.ToolTipSize.Height + 9);
        }
 
        private void PoisonToolTip_Draw(object sender, DrawToolTipEventArgs e)
        {
            ThemeStyle displayTheme = (Theme == ThemeStyle.Light) ? ThemeStyle.Dark : ThemeStyle.Light;
 
            Color backColor = PoisonPaint.BackColor.Form(displayTheme);
            Color borderColor = PoisonPaint.BorderColor.Button.Normal(displayTheme);
            Color foreColor = PoisonPaint.ForeColor.Label.Normal(displayTheme);
 
            using (SolidBrush b = new(backColor))
            {
                e.Graphics.FillRectangle(b, e.Bounds);
            }
 
            using (Pen p = new(borderColor))
            {
                e.Graphics.DrawRectangle(p, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1));
            }
 
            Font f = PoisonFonts.Default(13f);
            TextRenderer.DrawText(e.Graphics, e.ToolTipText, f, e.Bounds, foreColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
        }
 
        #endregion
    }
 
    #endregion
}