Visual Basic.NET 2008 > Windows Controls in VB.NET

Windows Controls in Visual Basic 2008 (VB.NET)

Jump to Table of Contents

In previous chapters, we explored the environment of Visual Basic and the principles of event-driven programming, which is the core of VB’s programming model. In the process, we briefly explored a few basic controls through the examples. The .NET Framework provides many more controls, and all of them have a multitude of trivial properties (such as Font, BackgroundColor, and so on), which you can set either in the Properties window or from within your code.

This chapter explores in depth the basic Windows controls: the controls you’ll use most often in your applications because they are the basic building blocks of typical rich client-user interfaces. Rather than look at controls’ background and foreground color, font, and other trivial properties, we’ll look at the properties unique to each control and see how these properties are used in building functional, rich user interfaces. In this chapter, you’ll learn how to do the following:

  • Use the TextBox control as a data-entry and text-editing tool - The TextBox control is the most common element of the Windows interface, short of the Button control, and it’s used to display and edit text. You can use a TextBox control to prompt users for a single line of text (such as a product name) or a small document (a product’s detailed description).

  • Use the ListBox, CheckedListBox, and ComboBox controls to present lists of items - The ListBox control contains a list of items from which the user can select one or more, depending on the setting of the SelectionMode property.

  • Use the ScrollBar and TrackBar controls to enable users to specify sizes and positions with the mouse - The ScrollBar and TrackBar controls let the user specify a magnitude by scrolling a selector between its minimum and maximum values. The ScrollBar control uses some visual feedback to display the effects of scrolling on another entity, such as the current view in a long document.

In this chapter, we’ll also continue our discussion of the basic Windows controls with the controls that implement the common dialog boxes and the RichTextBox control.

The .NET Framework provides a set of controls for displaying common dialog boxes, such as the Open or Color dialog boxes. Each of these controls encapsulates a large amount of functionality that would take a lot of code to duplicate. The common dialog controls are fundamental components because they enable you to design user interfaces with the look and feel of a Windows application.

Besides the common dialog boxes, we’ll also explore the RichTextBox control, which is an advanced version of the TextBox control. The RichTextBox control provides all the functionality you’ll need to build a word processor — WordPad is actually built around the RichTextBox control. The RichTextBox control allows you to format text bymixing fonts and attributes, aligning paragraphs differently, and so on. You can also embed other objects in the document displayed in a RichTextBox, such as images. Sure, the RichTextBox control is nothing like a full-fledged word processor, but it’s a great tool for editing formatted text at runtime.

You’ll learn how to do the following at the end of this chapter:

  • Use the OpenFileDialog and SaveFileDialog controls to prompt users for filenames - Windows applications use certain controls to prompt users for common information, such as filenames, colors, and fonts. Visual Studio provides a set of controls, which are grouped in the Dialogs section of the Toolbox. All common dialog controls provide a ShowDialog method, which displays the corresponding dialog box in a modal way. The ShowDialog method returns a value of the DialogResult type, which indicates how the dialog box was closed, and you should examine this value before processing the data.

  • Use the ColorDialog and FontDialog controls to prompt users for colors and typefaces - The Color and Font dialog boxes allow you to prompt users for a color value and a font, respectively. Before showing the corresponding dialog box, set its Color or Font property according to the current selection, and then call the control’s ShowDialog method.

  • Use the RichTextBox control as an advanced text editor to present richly formatted text - The RichTextBox control is an enhanced TextBox control that can display multiple fonts and styles, format paragraphs with different styles, and provide a few more advanced text-editing features. Even if you don’t need the formatting features of this control, you can use it as an alternative to the TextBox control. At the very least, the RichTextBox control provides more editing features, a more-useful undo function, and more-flexible search features.

You'll also learn to do the following:

  • Create and present hierarchical lists by using the TreeView control - The TreeView control is used to display a list of hierarchically structured items. Each item in the TreeView control is represented by a TreeNode object. To access the nodes of the TreeView control, use the TreeView.Nodes collection. The nodes under a specific node (in other words, the child nodes) form another collection of Node objects, which you can access by using the expression TreeView.Nodes(i).Nodes. The basic property of the Node object is the Text property, which stores the node’s caption. The Node object exposes properties for manipulating its appearance (its foreground/background color, its font, and so on).

  • Create and present lists of structured items by using the ListView control - The ListView control stores a collection of ListViewItem objects, the Items collection, and can display them in several modes, as specified by the View property. Each ListViewItem object has a Text property and the SubItems collection. The subitems are not visible at runtime unless you set the control’s View property to Details and set up the control’s Columns collection. There must be a column for each subitem you want to display on the control.

Table of Contents

  1. VB.NET TextBox Control

    1. Text-Manipulation Properties of TextBox Control
    2. Text-Selection Properties of TextBox Control
    3. Text-Selection Methods of TextBox Control
    4. The TextEditor Project Using VB.NET TextBox Control
    5. Capturing/Handling Keystrokes
    6. Auto-complete Properties of a VB.NET TextBox Control
  2. The ListBox, CheckedListBox, and ComboBox Controls

    1. Adding, Removing and Accessing Items from the ListBox Control's Item Collection
    2. Selecting Items from a ListBox Control
    3. Adding and Removing Items from a ListBox Control
    4. Searching the ListBox Control
  3. VB.NET ComboBox Control

    1. Adding Items to a ComboBox at Runtime
  4. The ScrollBar and TrackBar Controls in VB 2008

  5. The CommonDialog Controls in VB.NET 2008

  6. The ColorDialog Control in VB 2008

  7. The FontDialog Control in VB 2008

  8. The OpenDialog and SaveDialog Controls

  9. The FolderBrowserDialog Control

  10. The RichTextBox Control in VB.NET 2008

    1. Text Manipulation and Formatting Properties of RichTextBox Control
    2. Advanced Editing Features & Searching in a RichTextBox Control
    3. Handling URLs and Displaying a Formatted Directory Listing in the RichTextBox Document
    4. The RichTextBoxPad Project (VB.NET RichTextBox) - VB 2008
  11. Understanding the ListView, TreeView, and ImageList Controls

    1. Tree and List Structures of TreeView Control
    2. The ImageList Control in Visual Basic.NET 2008
    3. The TreeView Control in Visual Basic.NET 2008
    4. Adding Nodes to a TreeView Control at Design Time
    5. Adding Nodes to a TreeView Control at Runtime
    6. TreeView Example Exercise 1
    7. TreeViewDemo - The Globe Example
    8. Scanning the TreeView Control
  12. The ListView Control

    1. ListView Items and Subitems
    2. The Items Collection and The SubItems Collection of The ListView Control
    3. The ListView Sample Project - VB.NET 2008
    4. Sorting the ListView Control
    5. The CustomExplorer Project using ListView and TreeView Controls

     
 
W3computing.com Copyright 2011 All Rights Reserved
 
  Home | Useful links | Contact us | Privacy Policy