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-2006 Novell, Inc. (http://www.novell.com)
23 // Peter Bartok pbartok@novell.com
24 // Daniel Nauck (dna(at)mono-project(dot)de)
30 using System.Collections;
31 using System.ComponentModel;
32 using System.ComponentModel.Design;
35 using System.Collections.Generic;
36 using System.Runtime.InteropServices;
39 namespace System.Windows.Forms {
43 [ClassInterface (ClassInterfaceType.AutoDispatch)]
44 [Designer ("System.Windows.Forms.Design.TextBoxDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
46 public class TextBox : TextBoxBase {
48 private ContextMenu menu;
49 private MenuItem undo;
51 private MenuItem copy;
52 private MenuItem paste;
53 private MenuItem delete;
54 private MenuItem select_all;
57 private bool use_system_password_char;
58 private AutoCompleteStringCollection auto_complete_custom_source;
59 private AutoCompleteMode auto_complete_mode = AutoCompleteMode.None;
60 private AutoCompleteSource auto_complete_source = AutoCompleteSource.None;
61 private AutoCompleteListBox auto_complete_listbox;
62 private string auto_complete_original_text;
63 private int auto_complete_selected_index = -1;
64 private List<string> auto_complete_matches;
65 private ComboBox auto_complete_cb_source;
67 #endregion // Variables
69 #region Public Constructors
72 scrollbars = RichTextBoxScrollBars.None;
73 alignment = HorizontalAlignment.Left;
74 this.LostFocus +=new EventHandler(TextBox_LostFocus);
75 this.RightToLeftChanged += new EventHandler (TextBox_RightToLeftChanged);
77 MouseWheel += new MouseEventHandler (TextBox_MouseWheel);
80 BackColor = SystemColors.Window;
81 ForeColor = SystemColors.WindowText;
82 backcolor_set = false;
84 SetStyle (ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, false);
85 SetStyle (ControlStyles.FixedHeight, true);
87 undo = new MenuItem(Locale.GetText("&Undo"));
88 cut = new MenuItem(Locale.GetText("Cu&t"));
89 copy = new MenuItem(Locale.GetText("&Copy"));
90 paste = new MenuItem(Locale.GetText("&Paste"));
91 delete = new MenuItem(Locale.GetText("&Delete"));
92 select_all = new MenuItem(Locale.GetText("Select &All"));
94 menu = new ContextMenu(new MenuItem[] { undo, new MenuItem("-"), cut, copy, paste, delete, new MenuItem("-"), select_all});
97 menu.Popup += new EventHandler(menu_Popup);
98 undo.Click += new EventHandler(undo_Click);
99 cut.Click += new EventHandler(cut_Click);
100 copy.Click += new EventHandler(copy_Click);
101 paste.Click += new EventHandler(paste_Click);
102 delete.Click += new EventHandler(delete_Click);
103 select_all.Click += new EventHandler(select_all_Click);
105 document.multiline = false;
108 #endregion // Public Constructors
110 #region Private & Internal Methods
112 void TextBox_RightToLeftChanged (object sender, EventArgs e)
117 private void TextBox_LostFocus (object sender, EventArgs e) {
119 document.InvalidateSelectionArea ();
121 if (auto_complete_listbox != null && auto_complete_listbox.Visible)
122 auto_complete_listbox.HideListBox (false);
127 private void TextBox_MouseWheel (object o, MouseEventArgs args)
129 if (auto_complete_listbox == null || !auto_complete_listbox.Visible)
132 int lines = args.Delta / 120;
133 auto_complete_listbox.Scroll (-lines);
136 private void ShowAutoCompleteListBox (bool is_backspace)
139 // We only support CustomSource by now
143 if (auto_complete_cb_source == null)
144 source = auto_complete_custom_source;
146 source = auto_complete_cb_source.Items;
148 if (source == null || source.Count == 0)
151 bool append = auto_complete_mode == AutoCompleteMode.Append || auto_complete_mode == AutoCompleteMode.SuggestAppend;
152 bool suggest = auto_complete_mode == AutoCompleteMode.Suggest || auto_complete_mode == AutoCompleteMode.SuggestAppend;
154 if (Text.Length == 0) {
155 if (auto_complete_listbox != null)
156 auto_complete_listbox.HideListBox (false);
160 if (auto_complete_matches == null)
161 auto_complete_matches = new List<string> ();
164 auto_complete_matches.Clear ();
166 for (int i = 0; i < source.Count; i++) {
167 string item_text = auto_complete_cb_source == null ? auto_complete_custom_source [i] :
168 auto_complete_cb_source.GetItemText (auto_complete_cb_source.Items [i]);
169 if (item_text.StartsWith (text, StringComparison.CurrentCultureIgnoreCase))
170 auto_complete_matches.Add (item_text);
173 auto_complete_matches.Sort ();
175 // Return if we have a single exact match
176 if ((auto_complete_matches.Count == 0) || (auto_complete_matches.Count == 1 &&
177 auto_complete_matches [0].Equals (text, StringComparison.CurrentCultureIgnoreCase))) {
179 if (auto_complete_listbox != null && auto_complete_listbox.Visible)
180 auto_complete_listbox.HideListBox (false);
184 auto_complete_selected_index = suggest ? -1 : 0;
187 if (auto_complete_listbox == null)
188 auto_complete_listbox = new AutoCompleteListBox (this);
190 // Show or update auto complete listbox contents
191 auto_complete_listbox.Location = PointToScreen (new Point (0, Height));
192 auto_complete_listbox.ShowListBox ();
195 if (append && !is_backspace)
196 AppendAutoCompleteMatch (0);
198 document.MoveCaret (CaretDirection.End);
201 internal void HideAutoCompleteList ()
203 if (auto_complete_listbox != null)
204 auto_complete_listbox.HideListBox (false);
207 bool IsAutoCompleteAvailable {
209 if (auto_complete_source == AutoCompleteSource.None || auto_complete_mode == AutoCompleteMode.None)
212 // We only support CustomSource by now
213 if (auto_complete_source != AutoCompleteSource.CustomSource || auto_complete_custom_source == null ||
214 auto_complete_custom_source.Count == 0)
221 internal ComboBox AutoCompleteInternalSource {
223 return auto_complete_cb_source;
226 auto_complete_cb_source = value;
230 internal bool CanNavigateAutoCompleteList {
232 if (auto_complete_mode == AutoCompleteMode.None)
234 if (auto_complete_matches == null || auto_complete_matches.Count == 0)
237 bool suggest_window_visible = auto_complete_listbox != null && auto_complete_listbox.Visible;
238 if (auto_complete_mode == AutoCompleteMode.Suggest && !suggest_window_visible)
245 bool NavigateAutoCompleteList (Keys key)
247 if (auto_complete_matches == null || auto_complete_matches.Count == 0)
250 bool suggest_window_visible = auto_complete_listbox != null && auto_complete_listbox.Visible;
251 if (!suggest_window_visible && auto_complete_mode == AutoCompleteMode.Suggest)
254 int index = auto_complete_selected_index;
260 index = auto_complete_matches.Count - 1;
264 if (index >= auto_complete_matches.Count)
268 if (auto_complete_mode == AutoCompleteMode.Append || !suggest_window_visible)
272 index = auto_complete_matches.Count - 1;
276 index -= auto_complete_listbox.page_size - 1;
282 if (auto_complete_mode == AutoCompleteMode.Append || !suggest_window_visible)
287 else if (index == auto_complete_matches.Count - 1)
290 index += auto_complete_listbox.page_size - 1;
291 if (index >= auto_complete_matches.Count)
292 index = auto_complete_matches.Count - 1;
299 // In SuggestAppend mode the navigation mode depends on the visibility of the suggest lb.
300 bool suggest = auto_complete_mode == AutoCompleteMode.Suggest || auto_complete_mode == AutoCompleteMode.SuggestAppend;
301 if (suggest && suggest_window_visible) {
302 Text = index == -1 ? auto_complete_original_text : auto_complete_matches [index];
303 auto_complete_listbox.HighlightedIndex = index;
305 // Append only, not suggest at all
306 AppendAutoCompleteMatch (index < 0 ? 0 : index);
308 auto_complete_selected_index = index;
309 document.MoveCaret (CaretDirection.End);
314 void AppendAutoCompleteMatch (int index)
316 Text = auto_complete_original_text + auto_complete_matches [index].Substring (auto_complete_original_text.Length);
317 SelectionStart = auto_complete_original_text.Length;
318 SelectionLength = auto_complete_matches [index].Length - auto_complete_original_text.Length;
323 private void UpdateAlignment ()
325 HorizontalAlignment new_alignment = alignment;
326 RightToLeft rtol = GetInheritedRtoL ();
328 if (rtol == RightToLeft.Yes) {
329 if (new_alignment == HorizontalAlignment.Left)
330 new_alignment = HorizontalAlignment.Right;
331 else if (new_alignment == HorizontalAlignment.Right)
332 new_alignment = HorizontalAlignment.Left;
335 document.alignment = new_alignment;
337 // MS word-wraps if alignment isn't left
339 if (alignment != HorizontalAlignment.Left) {
340 document.Wrap = true;
342 document.Wrap = word_wrap;
346 for (int i = 1; i <= document.Lines; i++) {
347 document.GetLine (i).Alignment = new_alignment;
350 document.RecalculateDocument (CreateGraphicsInternal ());
352 Invalidate (); // Make sure we refresh
355 internal override Color ChangeBackColor (Color backColor)
357 if (backColor == Color.Empty) {
360 backColor = SystemColors.Window;
362 backColor = SystemColors.Window;
364 backcolor_set = false;
370 void OnAutoCompleteCustomSourceChanged(object sender, CollectionChangeEventArgs e) {
371 if(auto_complete_source == AutoCompleteSource.CustomSource) {
372 //FIXME: handle add, remove and refresh events in AutoComplete algorithm.
376 #endregion // Private & Internal Methods
378 #region Public Instance Properties
380 [MonoTODO("AutoCompletion algorithm is currently not implemented.")]
381 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
383 [EditorBrowsable (EditorBrowsableState.Always)]
385 [Editor ("System.Windows.Forms.Design.ListControlStringCollectionEditor, " + Consts.AssemblySystem_Design,
386 "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
387 public AutoCompleteStringCollection AutoCompleteCustomSource {
389 if(auto_complete_custom_source == null) {
390 auto_complete_custom_source = new AutoCompleteStringCollection ();
391 auto_complete_custom_source.CollectionChanged += new CollectionChangeEventHandler (OnAutoCompleteCustomSourceChanged);
393 return auto_complete_custom_source;
396 if(auto_complete_custom_source == value)
399 if(auto_complete_custom_source != null) //remove eventhandler from old collection
400 auto_complete_custom_source.CollectionChanged -= new CollectionChangeEventHandler (OnAutoCompleteCustomSourceChanged);
402 auto_complete_custom_source = value;
404 if(auto_complete_custom_source != null)
405 auto_complete_custom_source.CollectionChanged += new CollectionChangeEventHandler (OnAutoCompleteCustomSourceChanged);
409 [MonoTODO("AutoCompletion algorithm is currently not implemented.")]
411 [EditorBrowsable (EditorBrowsableState.Always)]
412 [DefaultValue (AutoCompleteMode.None)]
413 public AutoCompleteMode AutoCompleteMode {
414 get { return auto_complete_mode; }
416 if(auto_complete_mode == value)
419 if((value < AutoCompleteMode.None) || (value > AutoCompleteMode.SuggestAppend))
420 throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for AutoCompleteMode", value));
422 auto_complete_mode = value;
426 [MonoTODO("AutoCompletion algorithm is currently not implemented.")]
428 [EditorBrowsable (EditorBrowsableState.Always)]
429 [DefaultValue (AutoCompleteSource.None)]
430 [TypeConverter (typeof (TextBoxAutoCompleteSourceConverter))]
431 public AutoCompleteSource AutoCompleteSource {
432 get { return auto_complete_source; }
434 if(auto_complete_source == value)
437 if(!Enum.IsDefined (typeof (AutoCompleteSource), value))
438 throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for AutoCompleteSource", value));
440 auto_complete_source = value;
444 [DefaultValue(false)]
445 [RefreshProperties (RefreshProperties.Repaint)]
446 public bool UseSystemPasswordChar {
448 return use_system_password_char;
452 if (use_system_password_char != value) {
453 use_system_password_char = value;
456 document.PasswordChar = PasswordChar.ToString ();
458 document.PasswordChar = string.Empty;
465 [DefaultValue(false)]
466 [MWFCategory("Behavior")]
467 public bool AcceptsReturn {
469 return accepts_return;
473 if (value != accepts_return) {
474 accepts_return = value;
479 [DefaultValue(CharacterCasing.Normal)]
480 [MWFCategory("Behavior")]
481 public CharacterCasing CharacterCasing {
483 return character_casing;
487 if (value != character_casing) {
488 character_casing = value;
495 [MWFCategory("Behavior")]
497 [RefreshProperties (RefreshProperties.Repaint)]
499 public char PasswordChar {
502 if (use_system_password_char) {
506 return password_char;
510 if (value != password_char) {
511 password_char = value;
513 document.PasswordChar = PasswordChar.ToString ();
515 document.PasswordChar = string.Empty;
517 this.CalculateDocument();
522 [DefaultValue(ScrollBars.None)]
524 [MWFCategory("Appearance")]
525 public ScrollBars ScrollBars {
527 return (ScrollBars)scrollbars;
531 if (!Enum.IsDefined (typeof (ScrollBars), value))
532 throw new InvalidEnumArgumentException ("value", (int) value,
533 typeof (ScrollBars));
535 if (value != (ScrollBars)scrollbars) {
536 scrollbars = (RichTextBoxScrollBars)value;
537 base.CalculateScrollBars();
544 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
545 public override int SelectionLength {
547 return base.SelectionLength;
550 base.SelectionLength = value;
555 public override string Text {
565 [DefaultValue(HorizontalAlignment.Left)]
567 [MWFCategory("Appearance")]
568 public HorizontalAlignment TextAlign {
574 if (value != alignment) {
579 OnTextAlignChanged(EventArgs.Empty);
583 #endregion // Public Instance Properties
586 public void Paste (string text)
588 document.ReplaceSelection (CaseAdjust (text), false);
591 OnTextChanged(EventArgs.Empty);
594 #region Protected Instance Methods
595 protected override CreateParams CreateParams {
597 return base.CreateParams;
602 protected override ImeMode DefaultImeMode {
604 return base.DefaultImeMode;
609 protected override void Dispose (bool disposing)
611 base.Dispose (disposing);
615 protected override bool IsInputKey (Keys keyData)
617 return base.IsInputKey (keyData);
620 protected override void OnGotFocus (EventArgs e)
623 if (selection_length == -1 && !has_been_focused)
624 SelectAllNoScroll ();
625 has_been_focused = true;
628 protected override void OnHandleCreated (EventArgs e)
630 base.OnHandleCreated (e);
634 protected override void OnMouseUp(MouseEventArgs mevent)
636 base.OnMouseUp (mevent);
640 protected virtual void OnTextAlignChanged (EventArgs e)
642 EventHandler eh = (EventHandler)(Events [TextAlignChangedEvent]);
647 protected override void WndProc (ref Message m)
649 switch ((Msg)m.Msg) {
652 if (!IsAutoCompleteAvailable)
655 Keys key_data = (Keys)m.WParam.ToInt32 ();
661 if (NavigateAutoCompleteList (key_data)) {
662 m.Result = IntPtr.Zero;
667 if (auto_complete_listbox != null && auto_complete_listbox.Visible)
668 auto_complete_listbox.HideListBox (false);
672 if (auto_complete_listbox != null && auto_complete_listbox.Visible)
673 auto_complete_listbox.HideListBox (false);
680 if (!IsAutoCompleteAvailable)
683 bool is_backspace = m.WParam.ToInt32 () == 8;
684 if (!Char.IsLetterOrDigit ((char)m.WParam) && !is_backspace) {
685 // Update Text and save it before returning
686 base.WndProc (ref m);
687 auto_complete_original_text = Text;
692 Text = auto_complete_original_text;
694 document.MoveCaret (CaretDirection.End);
696 // Need to call base.WndProc before to have access to
697 // the updated Text property value
698 base.WndProc (ref m);
699 auto_complete_original_text = Text;
700 ShowAutoCompleteListBox (is_backspace);
703 case Msg.WM_LBUTTONDOWN:
704 // When the textbox gets focus by LBUTTON (but not by middle or right)
705 // it does not do the select all / scroll thing.
706 has_been_focused = true;
707 FocusInternal (true);
713 #endregion // Protected Instance Methods
716 static object TextAlignChangedEvent = new object ();
718 public event EventHandler TextAlignChanged {
719 add { Events.AddHandler (TextAlignChangedEvent, value); }
720 remove { Events.RemoveHandler (TextAlignChangedEvent, value); }
724 #region Private Methods
726 internal override ContextMenu ContextMenuInternal {
728 ContextMenu res = base.ContextMenuInternal;
734 base.ContextMenuInternal = value;
738 internal void RestoreContextMenu ()
740 ContextMenuInternal = menu;
743 private void menu_Popup(object sender, EventArgs e) {
744 if (SelectionLength == 0) {
746 copy.Enabled = false;
752 if (SelectionLength == TextLength) {
753 select_all.Enabled = false;
755 select_all.Enabled = true;
759 undo.Enabled = false;
765 undo.Enabled = cut.Enabled = paste.Enabled = delete.Enabled = false;
769 private void undo_Click(object sender, EventArgs e) {
773 private void cut_Click(object sender, EventArgs e) {
777 private void copy_Click(object sender, EventArgs e) {
781 private void paste_Click(object sender, EventArgs e) {
785 private void delete_Click(object sender, EventArgs e) {
786 SelectedText = string.Empty;
789 private void select_all_Click(object sender, EventArgs e) {
792 #endregion // Private Methods
795 public override bool Multiline {
797 return base.Multiline;
801 base.Multiline = value;
805 protected override void OnBackColorChanged (EventArgs e)
807 base.OnBackColorChanged (e);
810 protected override void OnFontChanged (EventArgs e)
812 base.OnFontChanged (e);
815 protected override void OnHandleDestroyed (EventArgs e)
817 base.OnHandleDestroyed (e);
820 class AutoCompleteListBox : Control
826 internal int page_size;
828 int highlighted_index = -1;
829 bool user_defined_size;
831 Rectangle resizer_bounds;
833 const int DefaultDropDownItems = 7;
835 public AutoCompleteListBox (TextBox tb)
838 item_height = FontHeight + 2;
840 vscroll = new VScrollBar ();
841 vscroll.ValueChanged += VScrollValueChanged;
842 Controls.Add (vscroll);
845 InternalBorderStyle = BorderStyle.FixedSingle;
848 protected override CreateParams CreateParams {
850 CreateParams cp = base.CreateParams;
852 cp.Style ^= (int)WindowStyles.WS_CHILD;
853 cp.Style ^= (int)WindowStyles.WS_VISIBLE;
854 cp.Style |= (int)WindowStyles.WS_POPUP;
855 cp.ExStyle |= (int)WindowExStyles.WS_EX_TOPMOST | (int)WindowExStyles.WS_EX_TOOLWINDOW;
860 public int HighlightedIndex {
862 return highlighted_index;
865 if (value == highlighted_index)
868 if (highlighted_index != -1)
869 Invalidate (GetItemBounds (highlighted_index));
870 highlighted_index = value;
871 if (highlighted_index != -1)
872 Invalidate (GetItemBounds (highlighted_index));
874 if (highlighted_index != -1)
875 EnsureVisible (highlighted_index);
879 public void Scroll (int lines)
881 int max = vscroll.Maximum - page_size + 1;
882 int val = vscroll.Value + lines;
885 else if (val < vscroll.Minimum)
886 val = vscroll.Minimum;
891 public void EnsureVisible (int index)
893 if (index < top_item) {
894 vscroll.Value = index;
896 int max = vscroll.Maximum - page_size + 1;
897 int rows = Height / item_height;
898 if (index > top_item + rows - 1) {
899 index = index - rows + 1;
900 vscroll.Value = index > max ? max : index;
905 internal override bool ActivateOnShow {
911 void VScrollValueChanged (object o, EventArgs args)
913 if (top_item == vscroll.Value)
916 top_item = vscroll.Value;
917 last_item = GetLastVisibleItem ();
921 int GetLastVisibleItem ()
925 for (int i = top_item; i < owner.auto_complete_matches.Count; i++) {
926 int pos = i - top_item; // relative to visible area
927 if ((pos * item_height) + item_height >= top_y)
931 return owner.auto_complete_matches.Count - 1;
934 Rectangle GetItemBounds (int index)
936 int pos = index - top_item;
937 Rectangle bounds = new Rectangle (0, pos * item_height, Width, item_height);
939 bounds.Width -= vscroll.Width;
944 int GetItemAt (Point loc)
946 if (loc.Y > (last_item - top_item) * item_height + item_height)
949 int retval = loc.Y / item_height;
955 void LayoutListBox ()
957 int total_height = owner.auto_complete_matches.Count * item_height;
958 page_size = Math.Max (Height / item_height, 1);
959 last_item = GetLastVisibleItem ();
961 if (Height < total_height) {
962 vscroll.Visible = true;
963 vscroll.Maximum = owner.auto_complete_matches.Count - 1;
964 vscroll.LargeChange = page_size;
965 vscroll.Location = new Point (Width - vscroll.Width, 0);
966 vscroll.Height = Height - item_height;
968 vscroll.Visible = false;
970 resizer_bounds = new Rectangle (Width - item_height, Height - item_height,
971 item_height, item_height);
974 public void HideListBox (bool set_text)
977 owner.Text = owner.auto_complete_matches [HighlightedIndex];
983 public void ShowListBox ()
985 if (!user_defined_size) {
986 // This should call the Layout routine for us
987 int height = owner.auto_complete_matches.Count > DefaultDropDownItems ?
988 DefaultDropDownItems * item_height : (owner.auto_complete_matches.Count + 1) * item_height;
989 Size = new Size (owner.Width, height);
994 HighlightedIndex = -1;
1000 protected override void OnResize (EventArgs args)
1002 base.OnResize (args);
1008 protected override void OnMouseDown (MouseEventArgs args)
1010 base.OnMouseDown (args);
1012 if (!resizer_bounds.Contains (args.Location))
1015 user_defined_size = true;
1020 protected override void OnMouseMove (MouseEventArgs args)
1022 base.OnMouseMove (args);
1025 Point mouse_loc = Control.MousePosition;
1026 Point ctrl_loc = PointToScreen (Point.Empty);
1028 Size new_size = new Size (mouse_loc.X - ctrl_loc.X, mouse_loc.Y - ctrl_loc.Y);
1029 if (new_size.Height < item_height)
1030 new_size.Height = item_height;
1031 if (new_size.Width < item_height)
1032 new_size.Width = item_height;
1038 Cursor = resizer_bounds.Contains (args.Location) ? Cursors.SizeNWSE : Cursors.Default;
1040 int item_idx = GetItemAt (args.Location);
1042 HighlightedIndex = item_idx;
1045 protected override void OnMouseUp (MouseEventArgs args)
1047 base.OnMouseUp (args);
1049 int item_idx = GetItemAt (args.Location);
1050 if (item_idx != -1 && !resizing)
1057 internal override void OnPaintInternal (PaintEventArgs args)
1059 Graphics g = args.Graphics;
1060 Brush brush = ThemeEngine.Current.ResPool.GetSolidBrush (ForeColor);
1062 int highlighted_idx = HighlightedIndex;
1065 int last = GetLastVisibleItem ();
1066 for (int i = top_item; i <= last; i++) {
1067 Rectangle item_bounds = GetItemBounds (i);
1068 if (!item_bounds.IntersectsWith (args.ClipRectangle))
1071 if (i == highlighted_idx) {
1072 g.FillRectangle (SystemBrushes.Highlight, item_bounds);
1073 g.DrawString (owner.auto_complete_matches [i], Font, SystemBrushes.HighlightText, item_bounds);
1075 g.DrawString (owner.auto_complete_matches [i], Font, brush, item_bounds);
1080 ThemeEngine.Current.CPDrawSizeGrip (g, SystemColors.Control, resizer_bounds);
1087 internal class TextBoxAutoCompleteSourceConverter : EnumConverter
1089 public TextBoxAutoCompleteSourceConverter(Type type)
1093 public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
1095 StandardValuesCollection stdv = base.GetStandardValues(context);
1096 AutoCompleteSource[] arr = new AutoCompleteSource[stdv.Count];
1097 stdv.CopyTo(arr, 0);
1098 AutoCompleteSource[] arr2 = Array.FindAll(arr, delegate (AutoCompleteSource value) {
1099 // No "ListItems" in a TextBox.
1100 return value != AutoCompleteSource.ListItems;
1102 return new StandardValuesCollection(arr2);