This Adding and Removing Item from a ListBox control example (shown in Figure 4.4) demonstrates the basic operations of the ListBox control. The two ListBox controls on the form operate slightly differently. The first has the default configuration: Only one item can be selected at a time, and new items are appended after the existing… [Continue Reading]
Windows Controls
Searching the ListBox Control
Two of the most useful methods of the ListBox control are the FindString and FindStringExact methods, which allow you to quickly locate any item in the list. The FindString method locates a string that partially matches the one you’re searching for; FindStringExact finds an exact match. If you’re searching for Man, and the control contains… [Continue Reading]
ComboBox Control
The ComboBox control is similar to the ListBox control in the sense that it contains multiple items and the user may select one, but it typically occupies less space onscreen. The ComboBox is practically an expandable ListBox control, which can grow when the user wants to make a selection and retract after the selection is… [Continue Reading]
Adding Items to a ComboBox at Runtime
Although the ComboBox control allows users to enter text in the control’s edit box, it doesn’t provide a simple mechanism for adding new items at runtime. Let’s say you provide a ComboBox with city names. Users can type the first few characters and quickly locate the desired item. But what if you want to allow… [Continue Reading]
ScrollBar and TrackBar Controls
The ScrollBar and TrackBar controls let the user specify a magnitude by scrolling a selector between its minimum and maximum values. In some situations, the user doesn’t know in advance the exact value of the quantity to specify (in which case, a text box would suffice), so your application must provide a more-flexible mechanism for… [Continue Reading]
Common Dialog Controls
A rather tedious, but quite common, task in nearly every application is to prompt the user for filenames, font names and sizes, or colors to be used by the application. Designing your own dialog boxes for these purposes would be a hassle, not to mention that your applications wouldn’t conform to the basic Windows interface… [Continue Reading]
ColorDialog Control
The Color dialog box, shown in Figure 4.11, is one of the simplest dialog boxes. Its Color property returns the color selected by the user or sets the initially selected color when the user opens the dialog box. The following statements set the initial color of the ColorDialog control, display the dialog box, and then… [Continue Reading]
FontDialog Control
The Font dialog box, shown in Figure 4.12, lets the user review and select a font and then set its size and style. Optionally, users can also select the font’s color and even apply the current settings to the selected text on a control of the form without closing the dialog box, by clicking the… [Continue Reading]
OpenDialog and SaveDialog Controls
Open and Save As, the two most widely used common dialog boxes (see Figure 4.13), are implemented by the OpenFileDialog and SaveFileDialog controls. Nearly every application prompts users for filenames, and the .NET Framework provides two controls for this purpose. The two dialog boxes are nearly identical, and most of their properties are common, so… [Continue Reading]
FolderBrowserDialog Control
Sometimes we need to prompt users for a folder, rather than a filename. An application that processes files in batch mode shouldn’t force users to select the files to be processed. Instead, it should allow users to select a folder and process all files of a specific type in the folder (it could encrypt all… [Continue Reading]