-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiLevelComboBox.cs
More file actions
108 lines (95 loc) · 3.17 KB
/
MultiLevelComboBox.cs
File metadata and controls
108 lines (95 loc) · 3.17 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
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace XOutput
{
class MultiLevelComboBox : ComboBox {
ContextMenuStrip menu;
public new event EventHandler DropDown;
public new event EventHandler DropDownClosed;
public new event EventHandler SelectionChangeCommitted;
private bool _DroppedDown;
public MultiLevelComboBox()
: base()
{
base.DropDownStyle = ComboBoxStyle.DropDownList;
menu = new ContextMenuStrip();
base.Items.Add("");
base.SelectedItem = "";
}
public ToolStripMenuItem addMenu(string name, ToolStripMenuItem parent = null) {
ToolStripMenuItem item = new ToolStripMenuItem();
item.Text = name;
if (parent != null) {
parent.DropDownItems.Add(item);
} else {
menu.Items.Add(item);
}
return item;
}
public ToolStripMenuItem addOption(string name, ToolStripMenuItem parent = null, object tag = null) {
ToolStripMenuItem item = new ToolStripMenuItem();
item.Text = name;
item.Tag = tag;
item.Click += (sender, e) => selectValue(item);
if (parent != null)
{
parent.DropDownItems.Add(item);
}
else
{
menu.Items.Add(item);
}
return parent;
}
private void selectValue(ToolStripMenuItem m) {
Items[0] = m.Text;
DroppedDown = false;
if (SelectionChangeCommitted != null)
SelectionChangeCommitted(m, EventArgs.Empty);
}
private void showDropDown() {
menu.Show(this, new Point(0, Height));
menu.AutoSize = false;
menu.Width = Width;
if (DropDown != null)
DropDown(this, EventArgs.Empty);
}
private void hideDropDown() {
menu.Hide();
if (DropDownClosed != null)
DropDownClosed(this, EventArgs.Empty);
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case 0x87: //WM_GETDLGCODE
break;//Block key down messages
case 0x201: //WM_LBUTTONDOWN
DroppedDown = !DroppedDown;
break;
case 0x203: //WM_LBUTTONDBLCLK
DroppedDown = !DroppedDown;
break;
default:
base.WndProc(ref m);
break;
}
}
public new bool DroppedDown {
get { return _DroppedDown; }
set { _DroppedDown = value;
if (value) { showDropDown(); } else { hideDropDown(); }
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(false), ReadOnly(true)]
public new ComboBoxStyle DropDownStyle
{
get { return base.DropDownStyle; }
set { }
}
}
}