FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
MapWindow5/src/MW5.UI/Menu/ComboBoxMenuItem.cs at develop · MapWindow/MapWindow5 · GitHub
MapWindow
/
MapWindow5
Public
Notifications
You must be signed in to change notification settings
Fork
102
Star
308
Code
Issues
14
Pull requests
12
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
MapWindow5
/
src
/
MW5.UI
/
Menu
/
ComboBoxMenuItem.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
115 lines (97 loc) · 3.37 KB
Breadcrumbs
MapWindow5
/
src
/
MW5.UI
/
Menu
/
ComboBoxMenuItem.cs
Copy path
File metadata and controls
115 lines (97 loc) · 3.37 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Collections
.
Specialized
;
using
System
.
Diagnostics
;
using
System
.
Linq
;
using
System
.
Text
;
using
System
.
Threading
.
Tasks
;
using
System
.
Windows
.
Forms
;
using
MW5
.
Plugins
.
Events
;
using
MW5
.
Plugins
.
Interfaces
;
using
MW5
.
Shared
;
using
Syncfusion
.
Windows
.
Forms
.
Tools
.
XPMenus
;
namespace
MW5
.
UI
.
Menu
{
internal
class
ComboBoxMenuItem
:
MenuItem
,
IComboBoxMenuItem
{
private
int
_listenerCount
=
0
;
private
string
_lastValue
=
string
.
Empty
;
internal
ComboBoxMenuItem
(
BarItem
item
)
:
base
(
item
)
{
var
combo
=
ComboItem
;
combo
.
SizeToFit
=
true
;
combo
.
MaxDropDownItems
=
10
;
}
private
void
combo_Click
(
object
sender
,
EventArgs
e
)
{
var
combo
=
ComboItem
;
// the new value isn't assigned to TextBoxValue property when Enter is pressed
// http: //www.syncfusion.com/forums/28969/using-comboboxbaritem
// let's use this hack to get it
var
textBox
=
ReflectionHelper
.
GetInstanceField
(
combo
,
"ComboTextBox"
)
as
TextBoxBase
;
FireValueChanged
(
textBox
!=
null
?
textBox
.
Text
:
combo
.
TextBoxValue
)
;
}
private
void
FireValueChanged
(
string
newValue
)
{
// Make sure that the event passed to listeners only once.
// Both Click and TextBoxValueChange will be fired when user select and item
// while in other cases only one of them is fired.
if
(
newValue
==
_lastValue
)
return
;
_lastValue
=
newValue
;
var
handler
=
_valueChanged
;
if
(
handler
!=
null
)
{
handler
(
this
,
new
StringValueChangedEventArgs
(
newValue
)
)
;
}
}
private
ComboBoxBarItem
ComboItem
{
get
{
return
_item
as
ComboBoxBarItem
;
}
}
public
StringCollection
DataSource
{
get
{
return
ComboItem
.
ChoiceList
;
}
}
public
int
Width
{
get
{
return
ComboItem
.
MinWidth
;
}
set
{
ComboItem
.
MinWidth
=
value
;
}
}
private
EventHandler
<
StringValueChangedEventArgs
>
_valueChanged
;
public
event
EventHandler
<
StringValueChangedEventArgs
>
ValueChanged
{
add
{
if
(
_listenerCount
==
0
)
{
// fired when user selects item from list or presses Enter
ComboItem
.
Click
+=
combo_Click
;
// fired when user selects item from list or changes it with mouse wheel
ComboItem
.
TextBoxValueChange
+=
(
s
,
e
)
=>
FireValueChanged
(
e
.
NewValue
)
;
}
_valueChanged
+=
value
;
_listenerCount
++
;
}
remove
{
_listenerCount
--
;
if
(
_listenerCount
==
0
)
{
EventHelper
.
RemoveEventHandler
(
ComboItem
,
"Click"
)
;
EventHelper
.
RemoveEventHandler
(
ComboItem
,
"TextBoxValueChange"
)
;
}
_valueChanged
-=
value
;
}
}
public
void
Focus
(
)
{
ComboItem
.
Focus
(
)
;
}
public
override
string
Text
{
get
{
return
ComboItem
.
TextBoxValue
;
}
set
{
ComboItem
.
TextBoxValue
=
value
;
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL