2
2
3
3
using ReaLTaiizor . Colors ;
4
4
using ReaLTaiizor . Util ;
5
+ using System ;
5
6
using System . ComponentModel ;
6
7
using System . Drawing ;
7
8
using System . Drawing . Drawing2D ;
8
9
using System . Drawing . Text ;
10
+ using System . Linq ;
9
11
using System . Windows . Forms ;
10
12
11
13
#endregion
@@ -35,10 +37,10 @@ private ListBox ListBx
35
37
}
36
38
}
37
39
38
- private string [ ] _items = { "" } ;
40
+ private string [ ] _items = Array . Empty < string > ( ) ;
39
41
40
42
[ Category ( "Options" ) ]
41
- public string [ ] items
43
+ public string [ ] Items
42
44
{
43
45
get => _items ;
44
46
set
@@ -50,21 +52,37 @@ public string[] items
50
52
}
51
53
}
52
54
53
- public object [ ] ListItems
55
+ public object ListSelectedItem
54
56
{
55
57
get
56
58
{
57
- return ListBx . Items . Cast < object > ( ) . OfType < object > ( ) . ToArray ( ) ;
59
+ if ( Items . Any ( ) && Items . Count ( ) >= SelectedIndex )
60
+ {
61
+ return ListBx . Items [ SelectedIndex ] ;
62
+ }
63
+
64
+ return null ;
58
65
}
59
66
}
60
- public object ListSelectedItem => ListBx . Items [ SelectedIndex ] ;
61
-
67
+
62
68
[ Category ( "Colors" ) ]
63
69
public Color SelectedColor { get ; set ; } = ForeverLibrary . ForeverColor ;
64
70
65
- public string SelectedItem =>
71
+ public string SelectedItem
72
+ {
73
+ get
74
+ {
66
75
//return ListBx.SelectedItem.ToString();
67
- ( string ) ListBx . Items [ SelectedIndex ] ;
76
+
77
+ if ( Items . Any ( ) && Items . Count ( ) >= SelectedIndex )
78
+ {
79
+ return ( string ) ListSelectedItem ;
80
+ }
81
+
82
+ return string . Empty ;
83
+ }
84
+ set => ListBx . SelectedItem = value ;
85
+ }
68
86
69
87
public int SelectedIndex
70
88
{
@@ -77,7 +95,14 @@ public int SelectedIndex
77
95
return functionReturnValue ;
78
96
}
79
97
80
- return functionReturnValue ;
98
+ return ListBx . SelectedIndex ;
99
+ }
100
+ set
101
+ {
102
+ if ( Items . Any ( ) && Items . Count ( ) - 1 >= value && value >= 0 )
103
+ {
104
+ ListBx . SelectedIndex = value ;
105
+ }
81
106
}
82
107
}
83
108
@@ -96,7 +121,7 @@ public void ClearSelected()
96
121
97
122
public void Drawitem ( object sender , DrawItemEventArgs e )
98
123
{
99
- if ( e . Index < 0 )
124
+ if ( e . Index < 0 || ! Items . Any ( ) )
100
125
{
101
126
return ;
102
127
}
@@ -106,8 +131,8 @@ public void Drawitem(object sender, DrawItemEventArgs e)
106
131
107
132
e . Graphics . SmoothingMode = SmoothingMode . HighQuality ;
108
133
e . Graphics . PixelOffsetMode = PixelOffsetMode . HighQuality ;
109
- e . Graphics . InterpolationMode = InterpolationMode . HighQualityBicubic ;
110
134
e . Graphics . TextRenderingHint = TextRenderingHint . ClearTypeGridFit ;
135
+ e . Graphics . InterpolationMode = InterpolationMode . HighQualityBicubic ;
111
136
112
137
//-- if selected
113
138
if ( e . State . ToString ( ) . IndexOf ( "Selected," ) >= 0 )
@@ -133,6 +158,7 @@ public void Drawitem(object sender, DrawItemEventArgs e)
133
158
protected override void OnCreateControl ( )
134
159
{
135
160
base . OnCreateControl ( ) ;
161
+
136
162
if ( ! Controls . Contains ( ListBx ) )
137
163
{
138
164
Controls . Add ( ListBx ) ;
@@ -141,13 +167,11 @@ protected override void OnCreateControl()
141
167
142
168
public void AddRange ( object [ ] items )
143
169
{
144
- ListBx . Items . Remove ( "" ) ;
145
170
ListBx . Items . AddRange ( items ) ;
146
171
}
147
172
148
173
public void AddItem ( object item )
149
174
{
150
- ListBx . Items . Remove ( "" ) ;
151
175
ListBx . Items . Add ( item ) ;
152
176
}
153
177
@@ -156,10 +180,11 @@ public void AddItem(object item)
156
180
public ForeverListBox ( )
157
181
{
158
182
ListBx = new ListBox ( ) ;
183
+
159
184
SetStyle ( ControlStyles . AllPaintingInWmPaint | ControlStyles . UserPaint | ControlStyles . ResizeRedraw | ControlStyles . OptimizedDoubleBuffer , true ) ;
160
185
DoubleBuffered = true ;
161
186
162
- ListBx . DrawMode = System . Windows . Forms . DrawMode . OwnerDrawFixed ;
187
+ ListBx . DrawMode = DrawMode . OwnerDrawFixed ;
163
188
ListBx . ScrollAlwaysVisible = false ;
164
189
ListBx . HorizontalScrollbar = false ;
165
190
ListBx . BorderStyle = BorderStyle . None ;
@@ -189,7 +214,6 @@ protected override void OnPaint(PaintEventArgs e)
189
214
_with19 . PixelOffsetMode = PixelOffsetMode . HighQuality ;
190
215
_with19 . TextRenderingHint = TextRenderingHint . ClearTypeGridFit ;
191
216
_with19 . Clear ( BackColor ) ;
192
-
193
217
//-- Size
194
218
ListBx . Size = new ( Width - 6 , Height - 2 ) ;
195
219
0 commit comments