-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIconSymbol.cs
More file actions
114 lines (95 loc) · 3.05 KB
/
Copy pathIconSymbol.cs
File metadata and controls
114 lines (95 loc) · 3.05 KB
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
using FireBlade.WinInteropUtils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Data;
using System.Drawing;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Windows_Dialog_Box_Generator
{
public partial class IconSymbol : UserControl
{
private Symbol _sym;
private Image? _lastImage;
public Symbol Icon
{
get => _sym;
set
{
if (!Enum.IsDefined(typeof(Symbol), value))
throw new InvalidEnumArgumentException(nameof(value), (int)value, typeof(Symbol));
_sym = value;
// Remove the old image.
pictureBox1.Image = null;
_lastImage?.Dispose();
// Create and assign the new image.
_lastImage = (value switch
{
Symbol.Information => StockIconHelper.GetIcon(StockIcon.Information, StockIconOptions.SmallIcon),
Symbol.Warning => StockIconHelper.GetIcon(StockIcon.Warning, StockIconOptions.SmallIcon),
Symbol.Error => StockIconHelper.GetIcon(StockIcon.Error, StockIconOptions.SmallIcon),
Symbol.Help => StockIconHelper.GetIcon(StockIcon.Help, StockIconOptions.SmallIcon),
_ => null
})?.ToBitmap();
pictureBox1.Image = _lastImage;
// Change the icon of the tooltip to match.
toolTip1.ToolTipIcon = value switch
{
Symbol.Information => ToolTipIcon.Info,
Symbol.Warning => ToolTipIcon.Warning,
Symbol.Error => ToolTipIcon.Error,
_ => ToolTipIcon.None
};
}
}
private string _tip = string.Empty;
[Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))]
public string ToolTipText
{
get => _tip;
set
{
_tip = value;
toolTip1.SetToolTip(pictureBox1, value);
}
}
private string _tipTitle = string.Empty;
public string ToolTipTitle
{
get => _tipTitle;
set
{
_tipTitle = value;
toolTip1.ToolTipTitle = value;
}
}
public IconSymbol()
{
InitializeComponent();
}
protected override void OnHandleDestroyed(EventArgs e)
{
base.OnHandleDestroyed(e);
pictureBox1.Image = null;
_lastImage?.Dispose();
_lastImage = null;
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
Icon = Icon;
}
public enum Symbol
{
Information,
Warning,
Error,
Help
}
}
}