The TextBox control is the primary mechanism for displaying and entering text. It is a small text editor that provides all the basic text-editing facilities: inserting and selecting text, scrolling if the text doesn’t fit in the control’s area, and even exchanging text with other applications through the Clipboard. The TextBox control is an extremely… [Continue Reading]
Windows Controls
TextBox Control’s Text-Manipulation Properties
Most of the properties for manipulating text in a TextBox control are available at runtime only. This section presents a breakdown of each property. Text The most important property of the TextBox control is the Text property, which holds the control’s text. You can set this property at design time to display some text on… [Continue Reading]
TextBox Control’s Text-Selection Properties
The TextBox control provides three properties for manipulating the text selected by the user: SelectedText, SelectionStart, and SelectionLength. Users can select a range of text with a click-and-drag operation, and the selected text will appear in reverse color. You can access the selected text from within your code through the SelectedText property, and its location… [Continue Reading]
TextBox Control’s Text-Selection Methods
In addition to properties, the TextBox control exposes two methods for selecting text. You can select some text by using the Select method, whose syntax is shown next: The Select method is equivalent to setting the SelectionStart and SelectionLength properties. To select the characters 100 through 105 on the control, call the Select method, passing… [Continue Reading]
The TextEditor Project – TextBox Control
The TextEditor application, shown in Figure 4.2, demonstrates most of the TextBox control’s properties and methods described so far. TextEditor is a basic text editor that you can incorporate into your programs and customize for special applications. The TextEditor project’s main form is covered by a TextBox control, whose size is adjusted every time the… [Continue Reading]
Capturing/Handling Keystrokes – TextBox Control
The TextBox control has a single unique event, the TextChanged event, which is fired every time the text on the control is changed, either because the user has typed a character or because of a paste operation. Another event that is quite common in programming the TextBox control is the KeyPress event, which occurs every… [Continue Reading]
Auto-complete Properties – TextBox Control
One set of interesting properties of the TextBox control are the autocomplete properties. Have you noticed how Internet Explorer prompts you with possible matches as soon as you start typing an address or your username in a text box (or in the address bar of the browser)? You can easily implement such boxes with a… [Continue Reading]
ListBox and CheckedListBox Controls
The ListBox, CheckedListBox, and ComboBox controls present lists of choices, from which the user can select one or more. The ListBox control occupies a user-specified amount of space on the form and is populated with a list of items. If the list of items is longer than can fit on the control, a vertical scroll… [Continue Reading]
Manipulating ListBox Control’s Item Collection
To manipulate a ListBox control from within your application, you should be able to do the following: Add items to the list Remove items from the list Access individual items in the list The items in the list are represented by the Items collection. You use the members of the Items collection to access the… [Continue Reading]
Selecting Items from a ListBox Control
The ListBox control allows the user to select either one or multiple items, depending on the setting of the SelectionMode property. In a single-selection ListBox control, you can retrieve the selected item by using the SelectedItem property, and its index by using the SelectedIndex property. SelectedItem returns the selected item, which is an object. The… [Continue Reading]