1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2005 Novell, Inc.
23 // Jordi Mas i Hernandez, jordi@ximian.com
31 using System.Collections;
32 using System.ComponentModel;
33 using System.Reflection;
34 using System.ComponentModel.Design;
35 using System.ComponentModel.Design.Serialization;
36 using System.Runtime.InteropServices;
39 namespace System.Windows.Forms
42 [DefaultProperty("Items")]
43 [DefaultEvent("SelectedIndexChanged")]
44 [Designer ("System.Windows.Forms.Design.ComboBoxDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
45 public class ComboBox : ListControl
47 private DrawMode draw_mode;
48 private ComboBoxStyle dropdown_style;
49 private int dropdown_width;
50 private const int preferred_height = 20;
51 private int selected_index;
52 private object selected_item;
53 internal ObjectCollection items = null;
54 private bool suspend_ctrlupdate;
55 private int maxdrop_items;
56 private bool integral_height;
58 internal ComboBoxInfo combobox_info;
59 private readonly int def_button_width = 16;
61 private int max_length;
62 private ComboListBox listbox_ctrl;
63 private TextBox textbox_ctrl;
64 private bool process_textchanged_event;
67 public class ChildAccessibleObject : AccessibleObject {
68 private ComboBox owner;
69 private IntPtr handle;
71 public ChildAccessibleObject (ComboBox owner, IntPtr handle) {
76 public override string Name {
85 internal class ComboBoxInfo
87 internal int item_height; /* Item's height */
88 internal Rectangle textarea; /* Rectangle of the editable text area */
89 internal Rectangle textarea_drawable; /* Rectangle of the editable text area - decorations - button if present*/
90 internal Rectangle button_rect;
91 internal bool show_button; /* Is the DropDown button shown? */
92 internal ButtonState button_status; /* Drop button status */
93 internal int original_height; /* Control's height is recalculated for not Simple Styles */
94 internal Rectangle listbox_area; /* ListBox area in Simple combox, not used in the rest */
95 internal bool droppeddown; /* Is the associated ListBox dropped down? */
96 internal int combosimple_height; /* Simple default height */
98 public ComboBoxInfo ()
100 button_status = ButtonState.Normal;
104 original_height = -1;
105 combosimple_height = 150;
109 internal class ComboBoxItem
112 internal int ItemHeight; /* Only used for OwnerDrawVariable */
114 public ComboBoxItem (int index)
123 items = new ObjectCollection (this);
126 combobox_info = new ComboBoxInfo ();
127 combobox_info.item_height = FontHeight + 2;
128 dropdown_style = (ComboBoxStyle)(-1);
129 DropDownStyle = ComboBoxStyle.DropDown;
130 BackColor = ThemeEngine.Current.ColorWindow;
131 draw_mode = DrawMode.Normal;
133 selected_item = null;
135 suspend_ctrlupdate = false;
139 integral_height = true;
140 process_textchanged_event = true;
144 MouseDown += new MouseEventHandler (OnMouseDownCB);
145 MouseUp += new MouseEventHandler (OnMouseUpCB);
146 MouseMove += new MouseEventHandler (OnMouseMoveCB);
147 KeyDown +=new KeyEventHandler(OnKeyDownCB);
153 [EditorBrowsable (EditorBrowsableState.Never)]
154 public new event EventHandler BackgroundImageChanged;
156 public event DrawItemEventHandler DrawItem;
157 public event EventHandler DropDown;
158 public event EventHandler DropDownStyleChanged;
159 public event MeasureItemEventHandler MeasureItem;
162 [EditorBrowsable (EditorBrowsableState.Never)]
163 public new event PaintEventHandler Paint;
165 public event EventHandler SelectedIndexChanged;
166 public event EventHandler SelectionChangeCommitted;
169 #region Public Properties
170 public override Color BackColor {
171 get { return base.BackColor; }
173 if (base.BackColor == value)
176 base.BackColor = value;
182 [EditorBrowsable (EditorBrowsableState.Never)]
183 public override Image BackgroundImage {
184 get { return base.BackgroundImage; }
186 if (base.BackgroundImage == value)
189 base.BackgroundImage = value;
191 if (BackgroundImageChanged != null)
192 BackgroundImageChanged (this, EventArgs.Empty);
198 protected override CreateParams CreateParams {
199 get { return base.CreateParams;}
202 protected override Size DefaultSize {
203 get { return new Size (121, PreferredHeight); }
206 [RefreshProperties(RefreshProperties.Repaint)]
207 [DefaultValue (DrawMode.Normal)]
208 public DrawMode DrawMode {
209 get { return draw_mode; }
212 if (!Enum.IsDefined (typeof (DrawMode), value))
213 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for DrawMode", value));
215 if (draw_mode == value)
223 [DefaultValue (ComboBoxStyle.DropDown)]
224 [RefreshProperties(RefreshProperties.Repaint)]
225 public ComboBoxStyle DropDownStyle {
226 get { return dropdown_style; }
230 if (!Enum.IsDefined (typeof (ComboBoxStyle), value))
231 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for ComboBoxStyle", value));
233 if (dropdown_style == value)
236 if (dropdown_style == ComboBoxStyle.Simple) {
237 if (listbox_ctrl != null) {
238 Controls.RemoveImplicit (listbox_ctrl);
239 listbox_ctrl.Dispose ();
241 Height = combobox_info.original_height;
245 if (dropdown_style != ComboBoxStyle.DropDownList && value == ComboBoxStyle.DropDownList) {
246 if (textbox_ctrl != null) {
247 Controls.RemoveImplicit (textbox_ctrl);
248 textbox_ctrl.Dispose ();
253 dropdown_style = value;
255 if (dropdown_style == ComboBoxStyle.Simple) {
256 CBoxInfo.show_button = false;
257 combobox_info.original_height = Height;
258 Height = combobox_info.combosimple_height;
260 CreateComboListBox ();
262 if (IsHandleCreated == true) {
263 Controls.AddImplicit (listbox_ctrl);
267 CBoxInfo.show_button = true;
268 CBoxInfo.button_status = ButtonState.Normal;
271 if (dropdown_style != ComboBoxStyle.DropDownList && textbox_ctrl == null) {
272 textbox_ctrl = new TextBox ();
273 textbox_ctrl.BorderStyle = BorderStyle.None;
274 textbox_ctrl.TextChanged += new EventHandler (OnTextChangedEdit);
275 textbox_ctrl.KeyPress += new KeyPressEventHandler(textbox_ctrl_KeyPress);
276 textbox_ctrl.GotFocus += new EventHandler(textbox_ctrl_GotFocus);
277 textbox_ctrl.LostFocus += new EventHandler(textbox_ctrl_LostFocus);
279 if (IsHandleCreated == true) {
280 Controls.AddImplicit (textbox_ctrl);
284 if (DropDownStyleChanged != null)
285 DropDownStyleChanged (this, EventArgs.Empty);
292 public int DropDownWidth {
294 if (dropdown_width == -1)
297 return dropdown_width;
300 if (dropdown_width == value)
304 throw new ArgumentException ("The DropDownWidth value is less than one");
306 dropdown_width = value;
311 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
312 public bool DroppedDown {
314 if (dropdown_style == ComboBoxStyle.Simple)
317 return CBoxInfo.droppeddown;
320 if (dropdown_style == ComboBoxStyle.Simple)
328 listbox_ctrl.Hide ();
331 if (DropDown != null)
332 DropDown (this, EventArgs.Empty);
336 public override bool Focused {
337 get { return base.Focused; }
340 public override Color ForeColor {
341 get { return base.ForeColor; }
343 if (base.ForeColor == value)
346 base.ForeColor = value;
351 [DefaultValue (true)]
353 public bool IntegralHeight {
354 get { return integral_height; }
356 if (integral_height == value)
359 integral_height = value;
365 public int ItemHeight {
366 get { return combobox_info.item_height; }
369 throw new ArgumentException ("The item height value is less than zero");
371 combobox_info.item_height = value;
377 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
379 [Editor ("System.Windows.Forms.Design.ListControlStringCollectionEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
380 public ComboBox.ObjectCollection Items {
381 get { return items; }
386 public int MaxDropDownItems {
387 get { return maxdrop_items; }
389 if (maxdrop_items == value)
392 maxdrop_items = value;
398 public int MaxLength {
399 get { return max_length; }
401 if (max_length == value)
406 if (dropdown_style != ComboBoxStyle.DropDownList) {
412 textbox_ctrl.MaxLength = value;
417 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
419 public int PreferredHeight {
420 get { return preferred_height; }
424 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
425 public override int SelectedIndex {
426 get { return selected_index; }
428 if (value <= -2 || value >= Items.Count)
429 throw new ArgumentOutOfRangeException ("Index of out range");
431 if (selected_index == value)
434 selected_index = value;
436 if (dropdown_style != ComboBoxStyle.DropDownList) {
437 SetControlText (GetItemText (Items[selected_index]));
440 OnSelectedIndexChanged (new EventArgs ());
441 OnSelectedValueChanged (new EventArgs ());
442 OnSelectedItemChanged (new EventArgs ());
448 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
450 public object SelectedItem {
452 if (selected_index !=-1 && Items !=null && Items.Count > 0)
453 return Items[selected_index];
458 int index = Items.IndexOf (value);
463 if (selected_index == index)
466 selected_index = index;
468 if (dropdown_style != ComboBoxStyle.DropDownList) {
469 SetControlText (GetItemText (Items[selected_index]));
472 OnSelectedItemChanged (new EventArgs ());
478 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
479 public string SelectedText {
481 if (dropdown_style == ComboBoxStyle.DropDownList)
484 return textbox_ctrl.SelectedText;
487 if (dropdown_style == ComboBoxStyle.DropDownList) {
491 textbox_ctrl.SelectedText = value;
496 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
497 public int SelectionLength {
499 if (dropdown_style == ComboBoxStyle.DropDownList)
502 return textbox_ctrl.SelectionLength;
505 if (dropdown_style == ComboBoxStyle.DropDownList)
508 if (textbox_ctrl.SelectionLength == value)
511 textbox_ctrl.SelectionLength = value;
516 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
517 public int SelectionStart {
519 if (dropdown_style == ComboBoxStyle.DropDownList)
522 return textbox_ctrl.SelectionStart;
525 if (dropdown_style == ComboBoxStyle.DropDownList)
528 if (textbox_ctrl.SelectionStart == value)
531 textbox_ctrl.SelectionStart = value;
535 [DefaultValue (false)]
537 get { return sorted; }
549 public override string Text {
551 if (dropdown_style != ComboBoxStyle.DropDownList) {
552 if (textbox_ctrl != null) {
553 return textbox_ctrl.Text;
557 if (SelectedItem != null) {
558 return GetItemText (SelectedItem);
569 int index = FindString (value);
572 SelectedIndex = index;
576 if (dropdown_style != ComboBoxStyle.DropDownList) {
577 textbox_ctrl.Text = GetItemText (value);
582 #endregion Public Properties
584 #region Private Properties
585 internal ComboBoxInfo CBoxInfo {
586 get { return combobox_info; }
589 #endregion Private Properties
591 #region Public Methods
592 protected virtual void AddItemsCore (object[] value)
597 public void BeginUpdate ()
599 suspend_ctrlupdate = true;
602 protected override void Dispose (bool disposing)
604 if (disposing == true) {
605 if (listbox_ctrl != null) {
606 listbox_ctrl.Dispose ();
607 Controls.RemoveImplicit (listbox_ctrl);
611 if (textbox_ctrl != null) {
612 Controls.RemoveImplicit (textbox_ctrl);
613 textbox_ctrl.Dispose ();
618 base.Dispose (disposing);
621 public void EndUpdate ()
623 suspend_ctrlupdate = false;
627 public int FindString (string s)
629 return FindString (s, -1);
632 public int FindString (string s, int startIndex)
634 if (Items.Count == 0)
635 return -1; // No exception throwing if empty
637 if (startIndex < -1 || startIndex >= Items.Count - 1)
638 throw new ArgumentOutOfRangeException ("Index of out range");
641 for (int i = startIndex; i < Items.Count; i++) {
642 if ((GetItemText (Items[i])).StartsWith (s))
649 public int FindStringExact (string s)
651 return FindStringExact (s, -1);
654 public int FindStringExact (string s, int startIndex)
656 if (Items.Count == 0)
657 return -1; // No exception throwing if empty
659 if (startIndex < -1 || startIndex >= Items.Count - 1)
660 throw new ArgumentOutOfRangeException ("Index of out range");
663 for (int i = startIndex; i < Items.Count; i++) {
664 if ((GetItemText (Items[i])).Equals (s))
671 public int GetItemHeight (int index)
673 if (DrawMode == DrawMode.OwnerDrawVariable && IsHandleCreated == true) {
675 if (index < 0 || index >= Items.Count )
676 throw new ArgumentOutOfRangeException ("The item height value is less than zero");
678 if ((Items.GetComboBoxItem (index)).ItemHeight != -1) {
679 return (Items.GetComboBoxItem (index)).ItemHeight;
682 MeasureItemEventArgs args = new MeasureItemEventArgs (DeviceContext, index, ItemHeight);
683 OnMeasureItem (args);
684 (Items.GetComboBoxItem (index)).ItemHeight = args.ItemHeight;
685 return args.ItemHeight;
691 protected override bool IsInputKey (Keys keyData)
705 protected override void OnBackColorChanged (EventArgs e)
707 base.OnBackColorChanged (e);
710 protected override void OnDataSourceChanged (EventArgs e)
712 base.OnDataSourceChanged (e);
713 BindDataItems (items);
715 if (DataSource == null || DataManager == null) {
719 SelectedIndex = DataManager.Position;
723 protected override void OnDisplayMemberChanged (EventArgs e)
725 base.OnDisplayMemberChanged (e);
727 if (DataManager == null || !IsHandleCreated)
730 BindDataItems (items);
731 SelectedIndex = DataManager.Position;
734 protected virtual void OnDrawItem (DrawItemEventArgs e)
736 if (DrawItem != null && (DrawMode == DrawMode.OwnerDrawFixed || DrawMode == DrawMode.OwnerDrawVariable)) {
741 ThemeEngine.Current.DrawComboBoxItem (this, e);
744 protected virtual void OnDropDown (EventArgs e)
746 if (DropDown != null)
750 protected virtual void OnDropDownStyleChanged (EventArgs e)
752 if (DropDownStyleChanged != null)
753 DropDownStyleChanged (this, e);
756 protected override void OnFontChanged (EventArgs e)
758 base.OnFontChanged (e);
760 if (textbox_ctrl != null) {
761 textbox_ctrl.Font = Font;
764 combobox_info.item_height = FontHeight + 2;
768 protected override void OnForeColorChanged (EventArgs e)
770 base.OnForeColorChanged (e);
773 [EditorBrowsable(EditorBrowsableState.Advanced)]
774 protected override void OnGotFocus (EventArgs e) {
779 [EditorBrowsable(EditorBrowsableState.Advanced)]
780 protected override void OnLostFocus (EventArgs e) {
785 protected override void OnHandleCreated (EventArgs e)
787 base.OnHandleCreated (e);
789 if (listbox_ctrl != null) {
790 Controls.AddImplicit (listbox_ctrl);
792 if (dropdown_style == ComboBoxStyle.Simple)
793 Height = combobox_info.combosimple_height;
797 if (textbox_ctrl != null) {
798 Controls.AddImplicit (textbox_ctrl);
804 protected override void OnHandleDestroyed (EventArgs e)
806 base.OnHandleDestroyed (e);
809 protected override void OnKeyPress (KeyPressEventArgs e)
814 protected virtual void OnMeasureItem (MeasureItemEventArgs e)
816 if (MeasureItem != null)
817 MeasureItem (this, e);
820 protected override void OnParentBackColorChanged (EventArgs e)
822 base.OnParentBackColorChanged (e);
825 protected override void OnResize (EventArgs e)
828 AdjustHeightForDropDown ();
830 if (listbox_ctrl != null)
831 listbox_ctrl.CalcListBoxArea ();
836 protected override void OnSelectedIndexChanged (EventArgs e)
838 base.OnSelectedIndexChanged (e);
840 if (SelectedIndexChanged != null)
841 SelectedIndexChanged (this, e);
844 protected virtual void OnSelectedItemChanged (EventArgs e)
849 protected override void OnSelectedValueChanged (EventArgs e)
851 base.OnSelectedValueChanged (e);
854 protected virtual void OnSelectionChangeCommitted (EventArgs e)
856 if (SelectionChangeCommitted != null)
857 SelectionChangeCommitted (this, e);
860 protected override void RefreshItem (int index)
862 if (index < 0 || index >= Items.Count)
863 throw new ArgumentOutOfRangeException ("Index of out range");
865 if (draw_mode == DrawMode.OwnerDrawVariable) {
866 (Items.GetComboBoxItem (index)).ItemHeight = -1;
870 public void Select (int start, int lenght)
873 throw new ArgumentException ("Start cannot be less than zero");
876 throw new ArgumentException ("Start cannot be less than zero");
878 if (dropdown_style == ComboBoxStyle.DropDownList)
881 textbox_ctrl.Select (start, lenght);
884 public void SelectAll ()
886 if (dropdown_style == ComboBoxStyle.DropDownList)
889 textbox_ctrl.SelectAll ();
892 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
894 base.SetBoundsCore (x, y, width, height, specified);
897 protected override void SetItemCore (int index, object value)
899 if (index < 0 || index >= Items.Count)
902 Items[index] = value;
905 protected override void SetItemsCore (IList value)
907 Items.AddRange (value);
910 public override string ToString ()
912 return base.ToString () + ", Items.Count:" + Items.Count;
915 protected override void WndProc (ref Message m)
918 switch ((Msg) m.Msg) {
921 PaintEventArgs paint_event;
922 paint_event = XplatUI.PaintEventStart (Handle, true);
923 OnPaintCB (paint_event);
924 XplatUI.PaintEventEnd (Handle, true);
928 case Msg.WM_ERASEBKGND:
929 m.Result = (IntPtr) 1;
936 base.WndProc (ref m);
940 #endregion Public Methods
942 #region Private Methods
944 private void AdjustHeightForDropDown ()
946 if (dropdown_style == ComboBoxStyle.Simple)
949 int new_height = combobox_info.item_height + ThemeEngine.Current.DrawComboBoxEditDecorationTop () +
950 ThemeEngine.Current.DrawComboBoxEditDecorationBottom () + 2;
952 if (Height == new_height)
955 combobox_info.original_height = Height;
959 private void textbox_ctrl_KeyPress(object sender, KeyPressEventArgs e)
964 private void textbox_ctrl_GotFocus(object sender, EventArgs e )
969 private void textbox_ctrl_LostFocus(object sender, EventArgs e )
974 // Calcs the text area size
975 internal void CalcTextArea ()
977 combobox_info.textarea = ClientRectangle;
980 combobox_info.textarea.Height = ItemHeight + ThemeEngine.Current.DrawComboBoxEditDecorationTop () +
981 ThemeEngine.Current.DrawComboBoxEditDecorationBottom () + 2;
982 // TODO: Does the +2 change at different font resolutions?
984 /* Edit area - minus decorations (text drawable area) */
985 combobox_info.textarea_drawable = combobox_info.textarea;
986 combobox_info.textarea_drawable.Y += ThemeEngine.Current.DrawComboBoxEditDecorationTop ();
987 combobox_info.textarea_drawable.X += ThemeEngine.Current.DrawComboBoxEditDecorationLeft ();
988 combobox_info.textarea_drawable.Height -= ThemeEngine.Current.DrawComboBoxEditDecorationBottom ();
989 combobox_info.textarea_drawable.Height -= ThemeEngine.Current.DrawComboBoxEditDecorationTop();
990 combobox_info.textarea_drawable.Width -= ThemeEngine.Current.DrawComboBoxEditDecorationRight ();
991 combobox_info.textarea_drawable.Width -= ThemeEngine.Current.DrawComboBoxEditDecorationLeft ();
993 /* Non-drawable area */
994 Region area = new Region (ClientRectangle);
995 area.Exclude (combobox_info.textarea);
996 RectangleF bounds = area.GetBounds (DeviceContext);
997 combobox_info.listbox_area = new Rectangle ((int)bounds.X, (int)bounds.Y,
998 (int)bounds.Width, (int)bounds.Height);
1000 if (CBoxInfo.show_button) {
1001 combobox_info.textarea_drawable.Width -= def_button_width;
1003 combobox_info.button_rect = new Rectangle (combobox_info.textarea_drawable.X + combobox_info.textarea_drawable.Width,
1004 combobox_info.textarea_drawable.Y, def_button_width, combobox_info.textarea_drawable.Height);
1008 if (dropdown_style != ComboBoxStyle.DropDownList) { /* There is an edit control*/
1009 if (textbox_ctrl != null) {
1010 textbox_ctrl.Location = new Point (combobox_info.textarea_drawable.X, combobox_info.textarea_drawable.Y);
1011 textbox_ctrl.Size = new Size (combobox_info.textarea_drawable.Width, combobox_info.textarea_drawable.Height);
1015 if (listbox_ctrl != null && dropdown_style == ComboBoxStyle.Simple) {
1016 listbox_ctrl.Location = new Point (combobox_info.textarea.X, combobox_info.textarea.Y +
1017 combobox_info.textarea.Height);
1018 listbox_ctrl.CalcListBoxArea ();
1024 private void CreateComboListBox ()
1026 listbox_ctrl = new ComboListBox (this);
1029 internal void Draw (Rectangle clip, Graphics dc)
1031 // No edit control, we paint the edit ourselfs
1032 if (dropdown_style == ComboBoxStyle.DropDownList) {
1033 DrawItemState state = DrawItemState.None;
1034 Rectangle item_rect = combobox_info.textarea_drawable;
1035 item_rect.Height = ItemHeight + 2;
1037 if (has_focus == true) {
1038 state = DrawItemState.Selected;
1039 state |= DrawItemState.Focus;
1042 state |= DrawItemState.ComboBoxEdit;
1043 OnDrawItem (new DrawItemEventArgs (dc, Font, item_rect,
1044 selected_index, state, ForeColor, BackColor));
1047 if (DropDownStyle == ComboBoxStyle.Simple && clip.IntersectsWith (combobox_info.listbox_area) == true) {
1048 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (Parent.BackColor),
1049 combobox_info.listbox_area);
1052 if (CBoxInfo.show_button) {
1053 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ThemeEngine.Current.ColorControl),
1054 combobox_info.button_rect);
1056 ThemeEngine.Current.CPDrawComboButton (dc,
1057 combobox_info.button_rect, combobox_info.button_status);
1060 ThemeEngine.Current.DrawComboBoxEditDecorations (dc, this, combobox_info.textarea);
1063 internal void DropDownListBox ()
1065 if (DropDownStyle == ComboBoxStyle.Simple)
1068 if (listbox_ctrl == null) {
1069 CreateComboListBox ();
1072 listbox_ctrl.Location = PointToScreen (new Point (combobox_info.textarea.X, combobox_info.textarea.Y +
1073 combobox_info.textarea.Height));
1075 if (listbox_ctrl.ShowWindow () == true) {
1076 CBoxInfo.droppeddown = true;
1079 combobox_info.button_status = ButtonState.Pushed;
1080 if (dropdown_style == ComboBoxStyle.DropDownList) {
1081 Invalidate (combobox_info.textarea_drawable);
1085 internal void DropDownListBoxFinished ()
1087 if (DropDownStyle == ComboBoxStyle.Simple)
1090 combobox_info.button_status = ButtonState.Normal;
1091 Invalidate (combobox_info.button_rect);
1092 CBoxInfo.droppeddown = false;
1096 private int FindStringCaseInsensitive (string search)
1098 if (search.Length == 0) {
1102 for (int i = 0; i < Items.Count; i++)
1104 if (String.Compare (GetItemText (Items[i]), 0, search, 0, search.Length, true) == 0)
1111 private void OnKeyDownCB(object sender, KeyEventArgs e)
1116 SelectedIndex = Math.Max(SelectedIndex-1, 0);
1120 SelectedIndex = Math.Min(SelectedIndex+1, Items.Count-1);
1124 if (listbox_ctrl != null)
1125 SelectedIndex = Math.Max(SelectedIndex- (listbox_ctrl.page_size-1), 0);
1129 if (listbox_ctrl != null)
1130 SelectedIndex = Math.Min(SelectedIndex+(listbox_ctrl.page_size-1), Items.Count-1);
1138 internal virtual void OnMouseDownCB (object sender, MouseEventArgs e)
1140 /* Click On button*/
1143 if (dropdown_style == ComboBoxStyle.DropDownList) {
1144 hit_rect = combobox_info.textarea;
1146 hit_rect = combobox_info.button_rect;
1149 if (hit_rect.Contains (e.X, e.Y)) {
1150 if (clicked == false) {
1154 listbox_ctrl.Hide ();
1155 DropDownListBoxFinished ();
1158 Invalidate (combobox_info.button_rect);
1162 internal virtual void OnMouseMoveCB (object sender, MouseEventArgs e)
1164 /* When there are no items, act as a regular button */
1165 if (clicked == true && Items.Count == 0 &&
1166 combobox_info.button_rect.Contains (e.X, e.Y) == false) {
1167 DropDownListBoxFinished ();
1171 internal virtual void OnMouseUpCB (object sender, MouseEventArgs e)
1173 /* Click on button*/
1174 if (clicked == true && combobox_info.button_rect.Contains (e.X, e.Y)) {
1175 DropDownListBoxFinished ();
1179 private void OnPaintCB (PaintEventArgs pevent)
1181 if (Width <= 0 || Height <= 0 || Visible == false || suspend_ctrlupdate == true)
1184 /* Copies memory drawing buffer to screen*/
1185 Draw (ClientRectangle, pevent.Graphics);
1188 Paint (this, pevent);
1191 private void OnTextChangedEdit (object sender, EventArgs e)
1193 if (process_textchanged_event == false)
1196 int item = FindStringCaseInsensitive (textbox_ctrl.Text);
1201 listbox_ctrl.SetTopItem (item);
1202 listbox_ctrl.SetHighLightedItem (Items[item]);
1205 internal void SetControlText (string s)
1207 process_textchanged_event = false;
1208 textbox_ctrl.Text = s;
1209 process_textchanged_event = true;
1212 private void UpdatedItems ()
1214 if (dropdown_style != ComboBoxStyle.Simple)
1217 listbox_ctrl.UpdateLastVisibleItem ();
1218 listbox_ctrl.CalcListBoxArea ();
1219 listbox_ctrl.Refresh ();
1222 #endregion Private Methods
1226 ComboBox.ObjectCollection
1228 [ListBindableAttribute (false)]
1229 public class ObjectCollection : IList, ICollection, IEnumerable
1232 private ComboBox owner;
1233 internal ArrayList object_items = new ArrayList ();
1234 internal ArrayList combobox_items = new ArrayList ();
1236 public ObjectCollection (ComboBox owner)
1241 #region Public Properties
1242 public virtual int Count {
1243 get { return object_items.Count; }
1246 public virtual bool IsReadOnly {
1247 get { return false; }
1251 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1252 public virtual object this [int index] {
1254 if (index < 0 || index >= Count)
1255 throw new ArgumentOutOfRangeException ("Index of out range");
1257 return object_items[index];
1260 if (index < 0 || index >= Count)
1261 throw new ArgumentOutOfRangeException ("Index of out range");
1263 object_items[index] = value;
1267 bool ICollection.IsSynchronized {
1268 get { return false; }
1271 object ICollection.SyncRoot {
1272 get { return this; }
1275 bool IList.IsFixedSize {
1276 get { return false; }
1279 #endregion Public Properties
1281 #region Private Properties
1282 internal ArrayList ObjectItems {
1283 get { return object_items;}
1285 object_items = value;
1289 internal ArrayList ListBoxItems {
1290 get { return combobox_items;}
1292 combobox_items = value;
1295 #endregion Private Properties
1297 #region Public Methods
1298 public int Add (object item)
1302 idx = AddItem (item);
1303 owner.UpdatedItems ();
1307 public void AddRange (object[] items)
1309 foreach (object mi in items)
1312 owner.UpdatedItems ();
1315 public virtual void Clear ()
1317 owner.selected_index = -1;
1318 object_items.Clear ();
1319 combobox_items.Clear ();
1320 owner.UpdatedItems ();
1324 public virtual bool Contains (object obj)
1326 return object_items.Contains (obj);
1329 public void CopyTo (object[] dest, int arrayIndex)
1331 object_items.CopyTo (dest, arrayIndex);
1334 void ICollection.CopyTo (Array dest, int index)
1336 object_items.CopyTo (dest, index);
1339 public virtual IEnumerator GetEnumerator ()
1341 return object_items.GetEnumerator ();
1344 int IList.Add (object item)
1349 public virtual int IndexOf (object value)
1351 return object_items.IndexOf (value);
1354 public virtual void Insert (int index, object item)
1356 if (index < 0 || index > Count)
1357 throw new ArgumentOutOfRangeException ("Index of out range");
1359 ObjectCollection new_items = new ObjectCollection (owner);
1360 object sel_item = owner.SelectedItem;
1362 owner.BeginUpdate ();
1364 for (int i = 0; i < index; i++) {
1365 new_items.AddItem (ObjectItems[i]);
1368 new_items.AddItem (item);
1370 for (int i = index; i < Count; i++){
1371 new_items.AddItem (ObjectItems[i]);
1374 ObjectItems = new_items.ObjectItems;
1375 ListBoxItems = new_items.ListBoxItems;
1377 if (sel_item != null) {
1378 int idx = IndexOf (sel_item);
1379 owner.selected_index = idx;
1380 owner.listbox_ctrl.SetHighLightedItem (owner.Items[idx]);
1383 owner.EndUpdate (); // Calls UpdatedItems
1386 public virtual void Remove (object value)
1388 if (IndexOf (value) == owner.SelectedIndex)
1389 owner.SelectedItem = null;
1391 RemoveAt (IndexOf (value));
1395 public virtual void RemoveAt (int index)
1397 if (index < 0 || index >= Count)
1398 throw new ArgumentOutOfRangeException ("Index of out range");
1400 if (index == owner.SelectedIndex)
1401 owner.SelectedItem = null;
1403 object_items.RemoveAt (index);
1404 combobox_items.RemoveAt (index);
1405 owner.UpdatedItems ();
1407 #endregion Public Methods
1409 #region Private Methods
1410 private int AddItem (object item)
1412 int cnt = object_items.Count;
1413 object_items.Add (item);
1414 combobox_items.Add (new ComboBox.ComboBoxItem (cnt));
1418 internal void AddRange (IList items)
1420 foreach (object mi in items)
1423 owner.UpdatedItems ();
1426 internal ComboBox.ComboBoxItem GetComboBoxItem (int index)
1428 if (index < 0 || index >= Count)
1429 throw new ArgumentOutOfRangeException ("Index of out range");
1431 return (ComboBox.ComboBoxItem) combobox_items[index];
1434 internal void SetComboBoxItem (ComboBox.ComboBoxItem item, int index)
1436 if (index < 0 || index >= Count)
1437 throw new ArgumentOutOfRangeException ("Index of out range");
1439 combobox_items[index] = item;
1442 #endregion Private Methods
1448 internal class ComboListBox : Control
1450 private ComboBox owner;
1451 private VScrollBarLB vscrollbar_ctrl;
1452 private int top_item; /* First item that we show the in the current page */
1453 private int last_item; /* Last visible item */
1454 public object highlighted_item; /* Item that is currently selected */
1455 internal int page_size; /* Number of listbox items per page */
1456 private Rectangle textarea_drawable; /* Rectangle of the drawable text area */
1458 internal enum ItemNavigation
1468 class VScrollBarLB : VScrollBar
1470 public VScrollBarLB ()
1474 public void FireMouseDown (MouseEventArgs e)
1479 public void FireMouseUp (MouseEventArgs e)
1484 public void FireMouseMove (MouseEventArgs e)
1491 public ComboListBox (ComboBox owner) : base ()
1497 highlighted_item = null;
1499 MouseDown += new MouseEventHandler (OnMouseDownPUW);
1500 MouseUp += new MouseEventHandler (OnMouseUpPUW);
1501 MouseMove += new MouseEventHandler (OnMouseMovePUW);
1502 KeyDown += new KeyEventHandler (OnKeyDownPUW);
1503 Paint += new PaintEventHandler (OnPaintPUW);
1504 SetStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
1505 SetStyle (ControlStyles.ResizeRedraw | ControlStyles.Opaque, true);
1508 protected override CreateParams CreateParams
1511 CreateParams cp = base.CreateParams;
1512 if (owner != null && owner.DropDownStyle != ComboBoxStyle.Simple) {
1513 cp.Style = unchecked ((int)(WindowStyles.WS_POPUP | WindowStyles.WS_VISIBLE | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_CLIPCHILDREN));
1514 cp.ExStyle |= (int)(WindowStyles.WS_EX_TOOLWINDOW | WindowStyles.WS_EX_TOPMOST);
1520 #region Private Methods
1521 // Calcs the listbox area
1522 internal void CalcListBoxArea ()
1525 int item_height = owner.ItemHeight;
1526 bool show_scrollbar = false;
1528 if (owner.DropDownStyle == ComboBoxStyle.Simple) {
1529 width = owner.CBoxInfo.listbox_area.Width;
1530 height = owner.CBoxInfo.listbox_area.Height;
1532 if (owner.IntegralHeight == true) {
1533 int remaining = (height -
1534 ThemeEngine.Current.DrawComboListBoxDecorationBottom (owner.DropDownStyle) -
1535 ThemeEngine.Current.DrawComboListBoxDecorationTop (owner.DropDownStyle)) %
1538 if (remaining > 0) {
1539 height -= remaining;
1543 else { // DropDown or DropDownList
1545 width = owner.DropDownWidth;
1546 int count = (owner.Items.Count <= owner.MaxDropDownItems) ? owner.Items.Count : owner.MaxDropDownItems;
1548 if (owner.DrawMode == DrawMode.OwnerDrawVariable) {
1550 for (int i = 0; i < count; i++) {
1551 height += owner.GetItemHeight (i);
1555 height = (item_height - 2) * count;
1559 height += ThemeEngine.Current.DrawComboListBoxDecorationBottom (owner.DropDownStyle);
1560 height += ThemeEngine.Current.DrawComboListBoxDecorationTop (owner.DropDownStyle);
1563 if (owner.Items.Count <= owner.MaxDropDownItems) {
1565 /* Does not need vertical scrollbar*/
1566 if (vscrollbar_ctrl != null) {
1567 vscrollbar_ctrl.Visible = false;
1571 /* Need vertical scrollbar */
1572 if (vscrollbar_ctrl == null) {
1573 vscrollbar_ctrl = new VScrollBarLB ();
1574 vscrollbar_ctrl.Minimum = 0;
1575 vscrollbar_ctrl.SmallChange = 1;
1576 vscrollbar_ctrl.LargeChange = 1;
1577 vscrollbar_ctrl.Maximum = 0;
1578 vscrollbar_ctrl.ValueChanged += new EventHandler (VerticalScrollEvent);
1580 Controls.AddImplicit (vscrollbar_ctrl);
1583 vscrollbar_ctrl.Height = height - ThemeEngine.Current.DrawComboListBoxDecorationBottom (owner.DropDownStyle) -
1584 ThemeEngine.Current.DrawComboListBoxDecorationTop (owner.DropDownStyle);
1586 vscrollbar_ctrl.Location = new Point (width - vscrollbar_ctrl.Width - ThemeEngine.Current.DrawComboListBoxDecorationRight (owner.DropDownStyle),
1587 ThemeEngine.Current.DrawComboListBoxDecorationTop (owner.DropDownStyle));
1589 vscrollbar_ctrl.Maximum = owner.Items.Count - (owner.DropDownStyle == ComboBoxStyle.Simple ? page_size : owner.maxdrop_items);
1590 show_scrollbar = vscrollbar_ctrl.Visible = true;
1593 Size = new Size (width, height);
1594 textarea_drawable = ClientRectangle;
1595 textarea_drawable.Width = width;
1596 textarea_drawable.Height = height;
1598 // Exclude decorations
1599 textarea_drawable.X += ThemeEngine.Current.DrawComboListBoxDecorationLeft (owner.DropDownStyle);
1600 textarea_drawable.Y += ThemeEngine.Current.DrawComboListBoxDecorationTop (owner.DropDownStyle);
1601 textarea_drawable.Width -= ThemeEngine.Current.DrawComboListBoxDecorationRight (owner.DropDownStyle);
1602 textarea_drawable.Width -= ThemeEngine.Current.DrawComboListBoxDecorationLeft (owner.DropDownStyle);
1603 textarea_drawable.Height -= ThemeEngine.Current.DrawComboListBoxDecorationBottom (owner.DropDownStyle);
1604 textarea_drawable.Height -= ThemeEngine.Current.DrawComboListBoxDecorationTop (owner.DropDownStyle);
1606 if (vscrollbar_ctrl != null && show_scrollbar)
1607 textarea_drawable.Width -= vscrollbar_ctrl.Width;
1609 last_item = LastVisibleItem ();
1610 page_size = textarea_drawable.Height / (item_height - 2);
1613 private void Draw (Rectangle clip, Graphics dc)
1615 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush
1616 (owner.BackColor), clip);
1618 if (owner.Items.Count > 0) {
1619 Rectangle item_rect;
1620 DrawItemState state = DrawItemState.None;
1622 for (int i = top_item; i <= last_item; i++) {
1623 item_rect = GetItemDisplayRectangle (i, top_item);
1625 if (clip.IntersectsWith (item_rect) == false)
1629 state = DrawItemState.None;
1631 if (i == GetHighLightedIndex () ) {
1632 state |= DrawItemState.Selected;
1634 if (owner.DropDownStyle == ComboBoxStyle.DropDownList) {
1635 state |= DrawItemState.Focus;
1639 owner.OnDrawItem (new DrawItemEventArgs (dc, owner.Font, item_rect,
1640 i, state, owner.ForeColor, owner.BackColor));
1644 ThemeEngine.Current.DrawComboListBoxDecorations (dc, owner, ClientRectangle);
1647 public int GetHighLightedIndex ()
1649 return owner.Items.IndexOf (highlighted_item);
1652 public object GetHighLightedItem ()
1654 return highlighted_item;
1657 private Rectangle GetItemDisplayRectangle (int index, int first_displayble)
1659 if (index < 0 || index >= owner.Items.Count)
1660 throw new ArgumentOutOfRangeException ("GetItemRectangle index out of range.");
1662 Rectangle item_rect = new Rectangle ();
1663 int height = owner.GetItemHeight (index);
1665 item_rect.X = ThemeEngine.Current.DrawComboListBoxDecorationRight (owner.DropDownStyle);
1666 item_rect.Width = textarea_drawable.Width;
1667 item_rect.Y = ((height - 2) * (index - first_displayble));
1669 if (owner.dropdown_style == ComboBoxStyle.Simple)
1672 item_rect.Height = height;
1676 public void HideWindow ()
1678 if (owner.DropDownStyle == ComboBoxStyle.Simple)
1683 highlighted_item = -1;
1684 owner.DropDownListBoxFinished ();
1687 private int IndexFromPointDisplayRectangle (int x, int y)
1689 for (int i = top_item; i <= last_item; i++) {
1690 if (GetItemDisplayRectangle (i, top_item).Contains (x, y) == true)
1697 protected override bool IsInputKey (Keys keyData)
1699 return owner.IsInputKey (keyData);
1702 private int LastVisibleItem ()
1704 Rectangle item_rect;
1705 int top_y = textarea_drawable.Y + textarea_drawable.Height;
1708 for (i = top_item; i < owner.Items.Count; i++) {
1709 item_rect = GetItemDisplayRectangle (i, top_item);
1710 if (item_rect.Y + item_rect.Height > top_y) {
1717 private void NavigateItemVisually (ItemNavigation navigation)
1721 switch (navigation) {
1722 case ItemNavigation.Next: {
1723 if (GetHighLightedIndex () + 1 < owner.Items.Count) {
1725 if (GetHighLightedIndex () + 1 > last_item) {
1727 vscrollbar_ctrl.Value = top_item;
1729 item = GetHighLightedIndex () + 1;
1734 case ItemNavigation.Previous: {
1735 if (GetHighLightedIndex () > 0) {
1737 if (GetHighLightedIndex () - 1 < top_item) {
1739 vscrollbar_ctrl.Value = top_item;
1741 item = GetHighLightedIndex () - 1;
1746 case ItemNavigation.NextPage: {
1747 if (GetHighLightedIndex () + page_size - 1 >= owner.Items.Count) {
1748 top_item = owner.Items.Count - page_size;
1749 vscrollbar_ctrl.Value = top_item;
1750 item = owner.Items.Count - 1;
1753 if (GetHighLightedIndex () + page_size - 1 > last_item) {
1754 top_item = GetHighLightedIndex ();
1755 vscrollbar_ctrl.Value = GetHighLightedIndex ();
1758 item = GetHighLightedIndex () + page_size - 1;
1763 case ItemNavigation.PreviousPage: {
1765 /* Go to the first item*/
1766 if (GetHighLightedIndex () - (page_size - 1) <= 0) {
1769 vscrollbar_ctrl.Value = top_item;
1772 else { /* One page back */
1773 if (GetHighLightedIndex () - (page_size - 1) < top_item) {
1774 top_item = GetHighLightedIndex () - (page_size - 1);
1775 vscrollbar_ctrl.Value = top_item;
1778 item = GetHighLightedIndex () - (page_size - 1);
1789 SetHighLightedItem (owner.Items[item]);
1791 owner.OnSelectionChangeCommitted (new EventArgs ());
1793 if (owner.DropDownStyle == ComboBoxStyle.Simple) {
1794 owner.SetControlText (owner.GetItemText (owner.Items[item]));
1799 private void OnKeyDownPUW (object sender, KeyEventArgs e)
1801 switch (e.KeyCode) {
1803 NavigateItemVisually (ItemNavigation.Previous);
1807 NavigateItemVisually (ItemNavigation.Next);
1811 NavigateItemVisually (ItemNavigation.PreviousPage);
1815 NavigateItemVisually (ItemNavigation.NextPage);
1823 public void SetHighLightedItem (object item)
1825 Rectangle invalidate;
1827 if (GetHighLightedItem () == item)
1831 if (GetHighLightedIndex () != -1) {
1832 invalidate = GetItemDisplayRectangle (GetHighLightedIndex (), top_item);
1833 if (ClientRectangle.IntersectsWith (invalidate))
1834 Invalidate (invalidate);
1837 highlighted_item = item;
1839 if (highlighted_item != null) {
1841 invalidate = GetItemDisplayRectangle (GetHighLightedIndex (), top_item);
1842 if (ClientRectangle.IntersectsWith (invalidate))
1843 Invalidate (invalidate);
1848 public void SetTopItem (int item)
1851 UpdateLastVisibleItem ();
1855 private void OnMouseDownPUW (object sender, MouseEventArgs e)
1857 Rectangle scrollbar_screenrect;
1858 Point mouse_screen, scrollbar_screen;
1859 mouse_screen = PointToScreen (new Point (e.X, e.Y));
1861 /* Click on an element ? */
1862 int index = IndexFromPointDisplayRectangle (e.X, e.Y);
1864 owner.SelectedIndex = index;
1865 SetHighLightedItem (owner.Items[index]);
1866 owner.OnSelectionChangeCommitted (new EventArgs ());
1871 if (owner.DropDownStyle == ComboBoxStyle.Simple)
1874 /* Reroute event to scrollbar */
1875 if (vscrollbar_ctrl != null && vscrollbar_ctrl.Visible == true) {
1876 scrollbar_screenrect = vscrollbar_ctrl.ClientRectangle;
1877 scrollbar_screen = PointToScreen (vscrollbar_ctrl.Location);
1878 scrollbar_screenrect.X = scrollbar_screen.X;
1879 scrollbar_screenrect.Y = scrollbar_screen.Y;
1881 if (scrollbar_screenrect.Contains (mouse_screen)){
1882 Point pnt_client = vscrollbar_ctrl.PointToClient (mouse_screen);
1883 vscrollbar_ctrl.FireMouseDown (new MouseEventArgs (e.Button, e.Clicks,
1884 pnt_client.X, pnt_client.Y, e.Delta));
1885 } else { /* Click in a non-client area*/
1888 } else { /* Click in a non-client area*/
1893 private void OnMouseMovePUW (object sender, MouseEventArgs e)
1895 if (owner.DropDownStyle == ComboBoxStyle.Simple)
1898 int index = IndexFromPointDisplayRectangle (e.X, e.Y);
1901 SetHighLightedItem (owner.Items[index]);
1905 if (owner.DropDownStyle == ComboBoxStyle.Simple)
1908 /* Reroute event to scrollbar */
1909 if (vscrollbar_ctrl != null && vscrollbar_ctrl.Visible == true) {
1910 Rectangle scrollbar_screenrect;
1911 Point mouse_screen, scrollbar_screen;
1912 mouse_screen = PointToScreen (new Point (e.X, e.Y));
1914 scrollbar_screenrect = vscrollbar_ctrl.ClientRectangle;
1915 scrollbar_screen = PointToScreen (vscrollbar_ctrl.Location);
1916 scrollbar_screenrect.X = scrollbar_screen.X;
1917 scrollbar_screenrect.Y = scrollbar_screen.Y;
1919 if (scrollbar_screenrect.Contains (mouse_screen)){
1920 Point pnt_client = vscrollbar_ctrl.PointToClient (mouse_screen);
1922 vscrollbar_ctrl.FireMouseMove (new MouseEventArgs (e.Button, e.Clicks,
1923 pnt_client.X, pnt_client.Y, e.Delta));
1928 private void OnMouseUpPUW (object sender, MouseEventArgs e)
1930 if (owner.DropDownStyle == ComboBoxStyle.Simple)
1933 /* Reroute event to scrollbar */
1934 Rectangle scrollbar_screenrect;
1935 Point mouse_screen, scrollbar_screen;
1936 mouse_screen = PointToScreen (new Point (e.X, e.Y));
1938 if (vscrollbar_ctrl != null && vscrollbar_ctrl.Visible == true) {
1939 scrollbar_screenrect = vscrollbar_ctrl.ClientRectangle;
1940 scrollbar_screen = PointToScreen (vscrollbar_ctrl.Location);
1941 scrollbar_screenrect.X = scrollbar_screen.X;
1942 scrollbar_screenrect.Y = scrollbar_screen.Y;
1944 if (scrollbar_screenrect.Contains (mouse_screen)){
1945 Point pnt_client = vscrollbar_ctrl.PointToClient (mouse_screen);
1947 vscrollbar_ctrl.FireMouseUp (new MouseEventArgs (e.Button, e.Clicks,
1948 pnt_client.X, pnt_client.Y, e.Delta));
1953 private void OnPaintPUW (Object o, PaintEventArgs pevent)
1955 Draw (pevent.ClipRectangle,pevent.Graphics);
1958 public bool ShowWindow ()
1960 if (owner.DropDownStyle != ComboBoxStyle.Simple && owner.Items.Count == 0)
1963 SetHighLightedItem (owner.SelectedItem);
1964 int index = GetHighLightedIndex ();
1965 SetTopItem (index == -1 ? 0 : index );
1970 if (owner.DropDownStyle != ComboBoxStyle.Simple) {
1976 if (owner.DropDown != null) {
1977 owner.DropDown (owner, EventArgs.Empty);
1983 public void UpdateLastVisibleItem ()
1985 last_item = LastVisibleItem ();
1989 private void VerticalScrollEvent (object sender, EventArgs e)
1991 top_item = vscrollbar_ctrl.Value;
1992 UpdateLastVisibleItem ();
1996 #endregion Private Methods