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)
138 if (auto_complete_mode == AutoCompleteMode.None || auto_complete_source == AutoCompleteSource.None)
142 // We only support CustomSource by now
144 if (auto_complete_source != AutoCompleteSource.CustomSource)
148 if (auto_complete_cb_source == null)
149 source = auto_complete_custom_source;
151 source = auto_complete_cb_source.Items;
153 if (source == null || source.Count == 0)
156 bool append = auto_complete_mode == AutoCompleteMode.Append || auto_complete_mode == AutoCompleteMode.SuggestAppend;
157 bool suggest = auto_complete_mode == AutoCompleteMode.Suggest || auto_complete_mode == AutoCompleteMode.SuggestAppend;
159 if (Text.Length == 0) {
160 if (auto_complete_listbox != null)
161 auto_complete_listbox.HideListBox (false);
165 if (auto_complete_matches == null)
166 auto_complete_matches = new List<string> ();
169 auto_complete_matches.Clear ();
171 for (int i = 0; i < source.Count; i++) {
172 string item_text = auto_complete_cb_source == null ? auto_complete_custom_source [i] :
173 auto_complete_cb_source.GetItemText (auto_complete_cb_source.Items [i]);
174 if (item_text.StartsWith (text, StringComparison.CurrentCultureIgnoreCase))
175 auto_complete_matches.Add (item_text);
178 auto_complete_matches.Sort ();
180 // Return if we have a single exact match
181 if ((auto_complete_matches.Count == 0) || (auto_complete_matches.Count == 1 &&
182 auto_complete_matches [0].Equals (text, StringComparison.CurrentCultureIgnoreCase))) {
184 if (auto_complete_listbox != null && auto_complete_listbox.Visible)
185 auto_complete_listbox.HideListBox (false);
189 auto_complete_selected_index = suggest ? -1 : 0;
192 if (auto_complete_listbox == null)
193 auto_complete_listbox = new AutoCompleteListBox (this);
195 // Show or update auto complete listbox contents
196 auto_complete_listbox.Location = PointToScreen (new Point (0, Height));
197 auto_complete_listbox.ShowListBox ();
200 if (append && !is_backspace)
201 AppendAutoCompleteMatch (0);
203 document.MoveCaret (CaretDirection.End);
206 internal void HideAutoCompleteList ()
208 if (auto_complete_listbox != null)
209 auto_complete_listbox.HideListBox (false);
212 internal ComboBox AutoCompleteInternalSource {
214 return auto_complete_cb_source;
217 auto_complete_cb_source = value;
221 internal bool CanNavigateAutoCompleteList {
223 if (auto_complete_mode == AutoCompleteMode.None)
225 if (auto_complete_matches == null || auto_complete_matches.Count == 0)
228 bool suggest_window_visible = auto_complete_listbox != null && auto_complete_listbox.Visible;
229 if (auto_complete_mode == AutoCompleteMode.Suggest && !suggest_window_visible)
236 bool NavigateAutoCompleteList (Keys key)
238 if (auto_complete_matches == null || auto_complete_matches.Count == 0)
241 bool suggest_window_visible = auto_complete_listbox != null && auto_complete_listbox.Visible;
242 if (!suggest_window_visible && auto_complete_mode == AutoCompleteMode.Suggest)
245 int index = auto_complete_selected_index;
251 index = auto_complete_matches.Count - 1;
255 if (index >= auto_complete_matches.Count)
259 if (auto_complete_mode == AutoCompleteMode.Append || !suggest_window_visible)
263 index = auto_complete_matches.Count - 1;
267 index -= auto_complete_listbox.page_size - 1;
273 if (auto_complete_mode == AutoCompleteMode.Append || !suggest_window_visible)
278 else if (index == auto_complete_matches.Count - 1)
281 index += auto_complete_listbox.page_size - 1;
282 if (index >= auto_complete_matches.Count)
283 index = auto_complete_matches.Count - 1;
290 // In SuggestAppend mode the navigation mode depends on the visibility of the suggest lb.
291 bool suggest = auto_complete_mode == AutoCompleteMode.Suggest || auto_complete_mode == AutoCompleteMode.SuggestAppend;
292 if (suggest && suggest_window_visible) {
293 Text = index == -1 ? auto_complete_original_text : auto_complete_matches [index];
294 auto_complete_listbox.HighlightedIndex = index;
296 // Append only, not suggest at all
297 AppendAutoCompleteMatch (index < 0 ? 0 : index);
299 auto_complete_selected_index = index;
300 document.MoveCaret (CaretDirection.End);
305 void AppendAutoCompleteMatch (int index)
307 Text = auto_complete_original_text + auto_complete_matches [index].Substring (auto_complete_original_text.Length);
308 SelectionStart = auto_complete_original_text.Length;
309 SelectionLength = auto_complete_matches [index].Length - auto_complete_original_text.Length;
314 private void UpdateAlignment ()
316 HorizontalAlignment new_alignment = alignment;
317 RightToLeft rtol = GetInheritedRtoL ();
319 if (rtol == RightToLeft.Yes) {
320 if (new_alignment == HorizontalAlignment.Left)
321 new_alignment = HorizontalAlignment.Right;
322 else if (new_alignment == HorizontalAlignment.Right)
323 new_alignment = HorizontalAlignment.Left;
326 document.alignment = new_alignment;
328 // MS word-wraps if alignment isn't left
330 if (alignment != HorizontalAlignment.Left) {
331 document.Wrap = true;
333 document.Wrap = word_wrap;
337 for (int i = 1; i <= document.Lines; i++) {
338 document.GetLine (i).Alignment = new_alignment;
341 document.RecalculateDocument (CreateGraphicsInternal ());
343 Invalidate (); // Make sure we refresh
346 internal override Color ChangeBackColor (Color backColor)
348 if (backColor == Color.Empty) {
351 backColor = SystemColors.Window;
353 backColor = SystemColors.Window;
355 backcolor_set = false;
361 void OnAutoCompleteCustomSourceChanged(object sender, CollectionChangeEventArgs e) {
362 if(auto_complete_source == AutoCompleteSource.CustomSource) {
363 //FIXME: handle add, remove and refresh events in AutoComplete algorithm.
367 #endregion // Private & Internal Methods
369 #region Public Instance Properties
371 [MonoTODO("AutoCompletion algorithm is currently not implemented.")]
372 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
374 [EditorBrowsable (EditorBrowsableState.Always)]
376 [Editor ("System.Windows.Forms.Design.ListControlStringCollectionEditor, " + Consts.AssemblySystem_Design,
377 "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
378 public AutoCompleteStringCollection AutoCompleteCustomSource {
380 if(auto_complete_custom_source == null) {
381 auto_complete_custom_source = new AutoCompleteStringCollection ();
382 auto_complete_custom_source.CollectionChanged += new CollectionChangeEventHandler (OnAutoCompleteCustomSourceChanged);
384 return auto_complete_custom_source;
387 if(auto_complete_custom_source == value)
390 if(auto_complete_custom_source != null) //remove eventhandler from old collection
391 auto_complete_custom_source.CollectionChanged -= new CollectionChangeEventHandler (OnAutoCompleteCustomSourceChanged);
393 auto_complete_custom_source = value;
395 if(auto_complete_custom_source != null)
396 auto_complete_custom_source.CollectionChanged += new CollectionChangeEventHandler (OnAutoCompleteCustomSourceChanged);
400 [MonoTODO("AutoCompletion algorithm is currently not implemented.")]
402 [EditorBrowsable (EditorBrowsableState.Always)]
403 [DefaultValue (AutoCompleteMode.None)]
404 public AutoCompleteMode AutoCompleteMode {
405 get { return auto_complete_mode; }
407 if(auto_complete_mode == value)
410 if((value < AutoCompleteMode.None) || (value > AutoCompleteMode.SuggestAppend))
411 throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for AutoCompleteMode", value));
413 auto_complete_mode = value;
417 [MonoTODO("AutoCompletion algorithm is currently not implemented.")]
419 [EditorBrowsable (EditorBrowsableState.Always)]
420 [DefaultValue (AutoCompleteSource.None)]
421 [TypeConverter (typeof (TextBoxAutoCompleteSourceConverter))]
422 public AutoCompleteSource AutoCompleteSource {
423 get { return auto_complete_source; }
425 if(auto_complete_source == value)
428 if(!Enum.IsDefined (typeof (AutoCompleteSource), value))
429 throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for AutoCompleteSource", value));
431 auto_complete_source = value;
435 [DefaultValue(false)]
436 [RefreshProperties (RefreshProperties.Repaint)]
437 public bool UseSystemPasswordChar {
439 return use_system_password_char;
443 if (use_system_password_char != value) {
444 use_system_password_char = value;
447 document.PasswordChar = PasswordChar.ToString ();
449 document.PasswordChar = string.Empty;
456 [DefaultValue(false)]
457 [MWFCategory("Behavior")]
458 public bool AcceptsReturn {
460 return accepts_return;
464 if (value != accepts_return) {
465 accepts_return = value;
470 [DefaultValue(CharacterCasing.Normal)]
471 [MWFCategory("Behavior")]
472 public CharacterCasing CharacterCasing {
474 return character_casing;
478 if (value != character_casing) {
479 character_casing = value;
486 [MWFCategory("Behavior")]
488 [RefreshProperties (RefreshProperties.Repaint)]
490 public char PasswordChar {
493 if (use_system_password_char) {
497 return password_char;
501 if (value != password_char) {
502 password_char = value;
504 document.PasswordChar = PasswordChar.ToString ();
506 document.PasswordChar = string.Empty;
508 this.CalculateDocument();
513 [DefaultValue(ScrollBars.None)]
515 [MWFCategory("Appearance")]
516 public ScrollBars ScrollBars {
518 return (ScrollBars)scrollbars;
522 if (!Enum.IsDefined (typeof (ScrollBars), value))
523 throw new InvalidEnumArgumentException ("value", (int) value,
524 typeof (ScrollBars));
526 if (value != (ScrollBars)scrollbars) {
527 scrollbars = (RichTextBoxScrollBars)value;
528 base.CalculateScrollBars();
535 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
536 public override int SelectionLength {
538 return base.SelectionLength;
541 base.SelectionLength = value;
546 public override string Text {
556 [DefaultValue(HorizontalAlignment.Left)]
558 [MWFCategory("Appearance")]
559 public HorizontalAlignment TextAlign {
565 if (value != alignment) {
570 OnTextAlignChanged(EventArgs.Empty);
574 #endregion // Public Instance Properties
577 public void Paste (string text)
579 document.ReplaceSelection (CaseAdjust (text), false);
582 OnTextChanged(EventArgs.Empty);
585 #region Protected Instance Methods
586 protected override CreateParams CreateParams {
588 return base.CreateParams;
593 protected override ImeMode DefaultImeMode {
595 return base.DefaultImeMode;
600 protected override void Dispose (bool disposing)
602 base.Dispose (disposing);
606 protected override bool IsInputKey (Keys keyData)
608 return base.IsInputKey (keyData);
611 protected override void OnGotFocus (EventArgs e)
614 if (selection_length == -1 && !has_been_focused)
615 SelectAllNoScroll ();
616 has_been_focused = true;
619 protected override void OnHandleCreated (EventArgs e)
621 base.OnHandleCreated (e);
625 protected override void OnMouseUp(MouseEventArgs mevent)
627 base.OnMouseUp (mevent);
631 protected virtual void OnTextAlignChanged (EventArgs e)
633 EventHandler eh = (EventHandler)(Events [TextAlignChangedEvent]);
638 protected override void WndProc (ref Message m)
640 switch ((Msg)m.Msg) {
643 if (auto_complete_mode == AutoCompleteMode.None ||
644 auto_complete_source != AutoCompleteSource.CustomSource)
647 Keys key_data = (Keys)m.WParam.ToInt32 ();
653 if (NavigateAutoCompleteList (key_data)) {
654 m.Result = IntPtr.Zero;
659 if (auto_complete_listbox != null && auto_complete_listbox.Visible)
660 auto_complete_listbox.HideListBox (false);
664 if (auto_complete_listbox != null && auto_complete_listbox.Visible)
665 auto_complete_listbox.HideListBox (false);
672 if (auto_complete_mode == AutoCompleteMode.None ||
673 auto_complete_source != AutoCompleteSource.CustomSource)
676 bool is_backspace = m.WParam.ToInt32 () == 8;
677 if (!Char.IsLetterOrDigit ((char)m.WParam) && !is_backspace)
681 Text = auto_complete_original_text;
683 document.MoveCaret (CaretDirection.End);
685 // Need to call base.WndProc before to have access to
686 // the updated Text property value
687 base.WndProc (ref m);
688 auto_complete_original_text = Text;
689 ShowAutoCompleteListBox (is_backspace);
692 case Msg.WM_LBUTTONDOWN:
693 // When the textbox gets focus by LBUTTON (but not by middle or right)
694 // it does not do the select all / scroll thing.
695 has_been_focused = true;
696 FocusInternal (true);
702 #endregion // Protected Instance Methods
705 static object TextAlignChangedEvent = new object ();
707 public event EventHandler TextAlignChanged {
708 add { Events.AddHandler (TextAlignChangedEvent, value); }
709 remove { Events.RemoveHandler (TextAlignChangedEvent, value); }
713 #region Private Methods
715 internal override ContextMenu ContextMenuInternal {
717 ContextMenu res = base.ContextMenuInternal;
723 base.ContextMenuInternal = value;
727 internal void RestoreContextMenu ()
729 ContextMenuInternal = menu;
732 private void menu_Popup(object sender, EventArgs e) {
733 if (SelectionLength == 0) {
735 copy.Enabled = false;
741 if (SelectionLength == TextLength) {
742 select_all.Enabled = false;
744 select_all.Enabled = true;
748 undo.Enabled = false;
754 undo.Enabled = cut.Enabled = paste.Enabled = delete.Enabled = false;
758 private void undo_Click(object sender, EventArgs e) {
762 private void cut_Click(object sender, EventArgs e) {
766 private void copy_Click(object sender, EventArgs e) {
770 private void paste_Click(object sender, EventArgs e) {
774 private void delete_Click(object sender, EventArgs e) {
775 SelectedText = string.Empty;
778 private void select_all_Click(object sender, EventArgs e) {
781 #endregion // Private Methods
784 public override bool Multiline {
786 return base.Multiline;
790 base.Multiline = value;
794 protected override void OnBackColorChanged (EventArgs e)
796 base.OnBackColorChanged (e);
799 protected override void OnFontChanged (EventArgs e)
801 base.OnFontChanged (e);
804 protected override void OnHandleDestroyed (EventArgs e)
806 base.OnHandleDestroyed (e);
809 class AutoCompleteListBox : Control
815 internal int page_size;
817 int highlighted_index = -1;
818 bool user_defined_size;
820 Rectangle resizer_bounds;
822 const int DefaultDropDownItems = 7;
824 public AutoCompleteListBox (TextBox tb)
827 item_height = FontHeight + 2;
829 vscroll = new VScrollBar ();
830 vscroll.ValueChanged += VScrollValueChanged;
831 Controls.Add (vscroll);
834 InternalBorderStyle = BorderStyle.FixedSingle;
837 protected override CreateParams CreateParams {
839 CreateParams cp = base.CreateParams;
841 cp.Style ^= (int)WindowStyles.WS_CHILD;
842 cp.Style ^= (int)WindowStyles.WS_VISIBLE;
843 cp.Style |= (int)WindowStyles.WS_POPUP;
844 cp.ExStyle |= (int)WindowExStyles.WS_EX_TOPMOST | (int)WindowExStyles.WS_EX_TOOLWINDOW;
849 public int HighlightedIndex {
851 return highlighted_index;
854 if (value == highlighted_index)
857 if (highlighted_index != -1)
858 Invalidate (GetItemBounds (highlighted_index));
859 highlighted_index = value;
860 if (highlighted_index != -1)
861 Invalidate (GetItemBounds (highlighted_index));
863 if (highlighted_index != -1)
864 EnsureVisible (highlighted_index);
868 public void Scroll (int lines)
870 int max = vscroll.Maximum - page_size + 1;
871 int val = vscroll.Value + lines;
874 else if (val < vscroll.Minimum)
875 val = vscroll.Minimum;
880 public void EnsureVisible (int index)
882 if (index < top_item) {
883 vscroll.Value = index;
885 int max = vscroll.Maximum - page_size + 1;
886 int rows = Height / item_height;
887 if (index > top_item + rows - 1) {
888 index = index - rows + 1;
889 vscroll.Value = index > max ? max : index;
894 internal override bool ActivateOnShow {
900 void VScrollValueChanged (object o, EventArgs args)
902 if (top_item == vscroll.Value)
905 top_item = vscroll.Value;
906 last_item = GetLastVisibleItem ();
910 int GetLastVisibleItem ()
914 for (int i = top_item; i < owner.auto_complete_matches.Count; i++) {
915 int pos = i - top_item; // relative to visible area
916 if ((pos * item_height) + item_height >= top_y)
920 return owner.auto_complete_matches.Count - 1;
923 Rectangle GetItemBounds (int index)
925 int pos = index - top_item;
926 Rectangle bounds = new Rectangle (0, pos * item_height, Width, item_height);
928 bounds.Width -= vscroll.Width;
933 int GetItemAt (Point loc)
935 if (loc.Y > (last_item - top_item) * item_height + item_height)
938 int retval = loc.Y / item_height;
944 void LayoutListBox ()
946 int total_height = owner.auto_complete_matches.Count * item_height;
947 page_size = Math.Max (Height / item_height, 1);
948 last_item = GetLastVisibleItem ();
950 if (Height < total_height) {
951 vscroll.Visible = true;
952 vscroll.Maximum = owner.auto_complete_matches.Count - 1;
953 vscroll.LargeChange = page_size;
954 vscroll.Location = new Point (Width - vscroll.Width, 0);
955 vscroll.Height = Height - item_height;
957 vscroll.Visible = false;
959 resizer_bounds = new Rectangle (Width - item_height, Height - item_height,
960 item_height, item_height);
963 public void HideListBox (bool set_text)
966 owner.Text = owner.auto_complete_matches [HighlightedIndex];
972 public void ShowListBox ()
974 if (!user_defined_size) {
975 // This should call the Layout routine for us
976 int height = owner.auto_complete_matches.Count > DefaultDropDownItems ?
977 DefaultDropDownItems * item_height : (owner.auto_complete_matches.Count + 1) * item_height;
978 Size = new Size (owner.Width, height);
983 HighlightedIndex = -1;
989 protected override void OnResize (EventArgs args)
991 base.OnResize (args);
997 protected override void OnMouseDown (MouseEventArgs args)
999 base.OnMouseDown (args);
1001 if (!resizer_bounds.Contains (args.Location))
1004 user_defined_size = true;
1009 protected override void OnMouseMove (MouseEventArgs args)
1011 base.OnMouseMove (args);
1014 Point mouse_loc = Control.MousePosition;
1015 Point ctrl_loc = PointToScreen (Point.Empty);
1017 Size new_size = new Size (mouse_loc.X - ctrl_loc.X, mouse_loc.Y - ctrl_loc.Y);
1018 if (new_size.Height < item_height)
1019 new_size.Height = item_height;
1020 if (new_size.Width < item_height)
1021 new_size.Width = item_height;
1027 Cursor = resizer_bounds.Contains (args.Location) ? Cursors.SizeNWSE : Cursors.Default;
1029 int item_idx = GetItemAt (args.Location);
1031 HighlightedIndex = item_idx;
1034 protected override void OnMouseUp (MouseEventArgs args)
1036 base.OnMouseUp (args);
1038 int item_idx = GetItemAt (args.Location);
1039 if (item_idx != -1 && !resizing)
1046 internal override void OnPaintInternal (PaintEventArgs args)
1048 Graphics g = args.Graphics;
1049 Brush brush = ThemeEngine.Current.ResPool.GetSolidBrush (ForeColor);
1051 int highlighted_idx = HighlightedIndex;
1054 int last = GetLastVisibleItem ();
1055 for (int i = top_item; i <= last; i++) {
1056 Rectangle item_bounds = GetItemBounds (i);
1057 if (!item_bounds.IntersectsWith (args.ClipRectangle))
1060 if (i == highlighted_idx) {
1061 g.FillRectangle (SystemBrushes.Highlight, item_bounds);
1062 g.DrawString (owner.auto_complete_matches [i], Font, SystemBrushes.HighlightText, item_bounds);
1064 g.DrawString (owner.auto_complete_matches [i], Font, brush, item_bounds);
1069 ThemeEngine.Current.CPDrawSizeGrip (g, SystemColors.Control, resizer_bounds);
1076 internal class TextBoxAutoCompleteSourceConverter : EnumConverter
1078 public TextBoxAutoCompleteSourceConverter(Type type)
1082 public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
1084 StandardValuesCollection stdv = base.GetStandardValues(context);
1085 AutoCompleteSource[] arr = new AutoCompleteSource[stdv.Count];
1086 stdv.CopyTo(arr, 0);
1087 AutoCompleteSource[] arr2 = Array.FindAll(arr, delegate (AutoCompleteSource value) {
1088 // No "ListItems" in a TextBox.
1089 return value != AutoCompleteSource.ListItems;
1091 return new StandardValuesCollection(arr2);