-
Notifications
You must be signed in to change notification settings - Fork 2
/
ToolStripCheckBox.cs
94 lines (81 loc) · 2.04 KB
/
ToolStripCheckBox.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
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Drawing;
namespace ZXNTCount
{
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)]
public class ToolStripCheckBox : MyCustomToolStripControlHost
{
// Call the base constructor passing in a CheckBox instance.
public ToolStripCheckBox()
: base(new CheckBox())
{
this.BackColor = Color.Transparent;
}
///
/// Gets the numeric up down control.
///
/// The numeric up down control.
public CheckBox CheckBoxControl
{
get
{
return Control as CheckBox;
}
}
///
/// Gets or sets the value.
///
/// The value.
public bool Checked
{
get
{
return CheckBoxControl.Checked;
}
set
{
CheckBoxControl.Checked = value;
}
}
///
/// Subscribe and unsubscribe the control events you wish to expose.
///
/// The c.
protected override void OnSubscribeControlEvents(Control c)
{
// Call the base so the base events are connected.
base.OnSubscribeControlEvents(c);
// Cast the control to a CheckBox control.
CheckBox checkBoxControl = (CheckBox)c;
// Add the event.
checkBoxControl.CheckedChanged += new EventHandler(OnCheckedChanged);
}
///
/// Subscribe and unsubscribe the control events you wish to expose.
///
/// The c.
protected override void OnUnsubscribeControlEvents(Control c)
{
// Call the base method so the basic events are unsubscribed.
base.OnUnsubscribeControlEvents(c);
// Cast the control to a CheckBox control.
CheckBox checkBoxControl = (CheckBox)c;
// Remove the event.
checkBoxControl.CheckedChanged -= new EventHandler(OnCheckedChanged);
}
// Declare the CheckedChanged event.
public event EventHandler CheckedChanged;
// Raise the CheckedChanged event.
private void OnCheckedChanged(object sender, EventArgs e)
{
if (CheckedChanged != null)
{
CheckedChanged(this, e);
}
}
}
}