-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tipsy.cs
97 lines (91 loc) · 3.11 KB
/
Tipsy.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace BF2statisticsLauncher
{
/// <summary>
/// Tipsy is a simple class that can Add and Remove tooltips
/// to form controls programatically during runtime.
/// </summary>
class Tipsy
{
/// <summary>
/// A list of tooltips for controls
/// </summary>
private static readonly Dictionary<string, ToolTip> ToolTips = new Dictionary<string, ToolTip>();
/// <summary>
/// Returns the controls tooptip object. If the control does not have
/// a tooltip, a new instance of a tooltip is returned instead
/// </summary>
/// <param name="controlName"></param>
/// <returns></returns>
public static ToolTip GetControlToolTip(string controlName)
{
if (ToolTips.ContainsKey(controlName))
{
return ToolTips[controlName];
}
else
{
ToolTip Tip = new ToolTip();
ToolTips.Add(controlName, Tip);
return Tip;
}
}
/// <summary>
/// Returns the controls tooptip object. If the control does not have
/// a tooltip, a new instance of a tooltip is returned instead
/// </summary>
/// <param name="control"></param>
/// <returns></returns>
public static ToolTip GetControlToolTip(Control control)
{
return GetControlToolTip(control.Name);
}
/// <summary>
/// Sets a tooltip object for a control
/// </summary>
/// <param name="control"></param>
/// <param name="text"></param>
public static void SetToolTip(Control control, string text)
{
SetToolTip(control, text, false);
}
/// <summary>
/// Sets a tooltip object for a control
/// </summary>
/// <param name="control"></param>
/// <param name="text"></param>
/// <param name="ShowAlways"></param>
public static void SetToolTip(Control control, string text, bool ShowAlways)
{
// Prevent cross thread errors
if (control.InvokeRequired)
{
control.Invoke((Action)delegate
{
ToolTip tt = Tipsy.GetControlToolTip(control);
tt.ShowAlways = ShowAlways;
tt.SetToolTip(control, text);
});
}
else
{
ToolTip tt = GetControlToolTip(control);
tt.SetToolTip(control, text);
}
}
/// <summary>
/// Removes any and all tooltips for a control
/// </summary>
/// <param name="control"></param>
public static void RemoveToolTip(Control control)
{
ToolTip T = ToolTips[control.Name];
T.Dispose();
ToolTips.Remove(control.Name);
}
}
}