Chapter 8. Selecting Windows Forms Controls

A control is a programming entity that has a graphical component. A control sits on a form and interacts with the user, providing information and possibly allowing the user to manipulate it. Text boxes, labels, buttons, scroll bars, drop-down lists, menu items, toolstrips, and just about everything else that you can see and interact with in a Windows application is a control.

Controls are an extremely important part of any interactive application. They give information to the user (Label, ToolTip, TreeView, PictureBox) and organize the information so that it's easier to understand (GroupBox, Panel, TabControl). They enable the user to enter data (TextBox, RichTextBox, ComboBox, MonthCalendar), select options (RadioButton, CheckBox, ListBox), tell the application to take action (Button, MenuStrip, ContextMenuStrip), and interact with objects outside of the application (OpenFileDialog, SaveFileDialog, PrintDocument, PrintPreviewDialog). Some controls also provide support for other controls (ImageList, ToolTip, ContextMenuStrip, ErrorProvider).

This chapter provides only a very brief description of the standard Windows Forms controls together with some tips that can help you decide which control to use for different purposes. Appendix G, "Windows Forms Controls and Components," covers the controls in much greater detail, describing each control's most useful properties, methods, and events.

CONTROLS OVERVIEW

Figure 8-1 shows the Visual Basic Toolbox displaying the standard Windows Forms controls. Because you can add and remove controls on the Toolbox, you may see a slightly different selection of tools on your computer.

Visual Basic provides a large number of standard controls for Windows Forms.

Figure 8.1. Visual Basic provides a large number of standard controls for Windows Forms.

The following table briefly describes the controls shown in Figure 8-1 in the order in which they appear in the figure (starting at the top, or row 1, and reading from left to right).

CONTROL

PURPOSE

Row 1

Pointer

This is the pointer tool, not a control. Click this tool to deselect any selected controls on a form. Then you can select new controls.

BackgroundWorker

Executes a task asynchronously and notifies the main program when it is finished.

BindingNavigator

Provides a user interface for navigating through a data source. For example, it provides buttons that let the user move back and forth through the data, add records, delete records, and so forth.

BindingSource

Encapsulates a form's data source and provides methods for navigating through the data.

Button

A simple push button. When the user clicks it, the program can perform some action.

CheckBox

A box that the user can check and clear.

CheckedListBox

A list of items with check boxes that the user can check and clear.

ColorDialog

Lets the user pick a standard or custom color.

ComboBox

A text box with an attached list or drop-down list that the user can use to enter or select a textual value.

ContextMenuStrip

A menu that appears when the user right-clicks a control. You set a control's ContextMenuStrip property to this control, and the rest is automatic.

Row 2

DataGridView

A powerful grid control that lets you display large amounts of complex data with hierarchical or Web-like relationships relatively easily.

DataSet

An in-memory store of data with properties similar to those of a relational database. It holds objects representing tables containing rows and columns, and can represent many database concepts such as indexes and foreign key relationships.

DateTimePicker

Lets the user select a date and time in one of several styles.

DirectoryEntry

Represents a node in an Active Directory hierarchy.

DirectorySearcher

Performs searches of an Active Directory hierarchy.

DomainUpDown

Lets the user scroll through a list of choices by clicking up-arrow and down-arrow buttons.

ErrorProvider

Displays an error indicator next to a control that is associated with an error.

EventLog

Provides access to Windows event logs.

FileSystemWatcher

Notifies the application of changes to a directory or file.

FlowLayoutPanel

Displays the controls it contains in rows or columns. For example, when laying out rows, it places controls next to each other horizontally in a row until it runs out of room and then it starts a new row.

Row 3

FolderBrowserDialog

Lets the user select a folder.

FontDialog

Lets the user specify a font's characteristics (name, size, boldness, and so forth).

GroupBox

Groups related controls for clarity. It also defines a default RadioButton group for any RadioButtons that it contains.

HelpProvider

Displays help for controls that have help if the user sets focus on the control and presses F1.

HScrollBar

A horizontal scroll bar.

ImageList

Contains a series of images that other controls can use. For example, the images that a TabControl displays on its tabs are stored in an associated ImageList control. Your code can also pull images from an ImageList for its own use.

Label

Displays text that the user cannot modify or select by clicking and dragging.

LinkLabel

Displays a label, parts of which may be hyperlinks. When the user clicks a hyperlink, the program can take some action.

ListBox

Displays a list of items that the user can select. Depending on the control's properties, the user can select one or several items.

ListView

Displays a list of items in one of four possible views: LargeIcon, SmallIcon, List, and Details.

Row 4

MaskedTextBox

A text box that requires the input to match a specific format (such as a phone number or ZIP code format).

MenuStrip

Represents the form's main menus, submenus, and menu items.

MessageQueue

Provides communication between different applications.

MonthCalendar

Displays a calendar that allows the user to select a range of dates.

NotifyIcon

Displays an icon in the system tray or status area.

NumericUpDown

Lets the user change a number by clicking up-arrow and down-arrow buttons.

OpenFileDialog

Lets the user select a file for opening.

PageSetupDialog

Lets the user specify properties for printed pages. For example, it lets the user specify the printer's paper tray, page size, margins, and orientation (portrait or landscape).

Panel

A control container. Using the control's Anchor and Dock properties, you can make the control resize itself so that its child controls resize themselves in turn. The control can automatically provide scroll bars and defines a RadioButton group for any RadioButtons that it contains.

PerformanceCounter

Provides access to Windows performance counters.

Row 5

PictureBox

Displays a picture. Also provides a useful drawing surface.

PrintDialog

Displays a standard print dialog box. The user can select the printer, pages to print, and printer settings.

PrintDocument

Represents output to be sent to the printer. A program can use this object to print and display print previews.

PrintPreviewControl

Displays a print preview within one of the application's forms.

PrintPreviewDialog

Displays a print preview in a standard dialog box.

Process

Allows the program to interact with processes, and to start and stop them.

ProgressBar

Displays a series of colored bars to show the progress of a long operation.

PropertyGrid

Displays information about an object in a format similar to the one used by the Properties window at design time.

RadioButton

Represents one of an exclusive set of options. When the user selects a RadioButton, Visual Basic deselects all other RadioButton controls in the same group. Groups are defined by GroupBox and Panels controls and the Form class.

RichTextBox

A text box that supports Rich Text extensions. The control can display different pieces of text with different font names, sizes, bolding, and so forth. It also provides paragraph-level formatting for justification, bullets, hanging indentation, and more.

Row 6

SaveFileDialog

Lets the user select the name of a file where the program will save data.

SerialPort

Represents a serial port and provides methods for controlling, reading, and writing it.

ServiceController

Represents a Windows service and lets you manipulate services.

SplitContainer

Lets the user drag a divider vertically or horizontally to split available space between two areas within the control.

Splitter

Provides a divider that the user can drag to split available space between two controls. The Dock properties and stacking orders of the controls and the Splitter determine how the controls are arranged and resized. The SplitContainer control automatically provides a Splitter between two containers, so it is usually easier and less confusing to use.

StatusStrip

Provides an area (usually at the bottom of the form) where the application can display status messages, small pictures, and other indicators of the application's state.

TabControl

Displays a series of tabs attached to pages that contain their own controls. The user clicks a tab to display the associated page.

TableLayoutPanel

Displays the controls it contains in a grid.

TextBox

Displays some text that the user can edit.

Timer

Triggers an event periodically. The program can take action when the event occurs.

Row 7

ToolStrip

Displays a series of buttons, dropdowns, and other tools that let the user control the application.

ToolStripContainer

A container that allows a ToolStrip control to dock to some or all of its edges. You might dock a ToolStripContainer to a form to allow the user to dock a ToolStrip to each of the form's edges.

ToolTip

Displays a tooltip if the user hovers the mouse over an associated control.

TrackBar

Allows the user to drag a pointer along a bar to select a numeric value.

TreeView

Displays hierarchical data in a graphical, tree-like form.

VScrollBar

A vertical scroll bar.

WebBrowser

A web browser in a control. You can place this control on a form and use its methods to navigate to a web page. The control displays the results exactly as if the user were using a standalone browser. One handy use for this control is displaying Web-based help.

Example program UseToolStripContainer, which is available for download on the book's web site, contains a ToolStripContainer that holds two ToolStrip controls that you can drag and dock to the sides of the ToolStripContainer.

See Appendix G for detailed descriptions of the controls.

CHOOSING CONTROLS

Keeping all of the intricacies of each of these controls in mind at once is a daunting task. With so many powerful tools to choose from, it's not always easy to pick the one that's best for a particular situation.

To simplify error-handling code, you should generally pick the most restrictive control that can accomplish a given task, because more restrictive controls give the user fewer options for entering invalid data.

For example, suppose that the user must pick from the choices Small, Medium, and Large. The application could let the user type a value in a TextBox control, but then the user could type Weasel. The program would need to verify that the user typed one of the valid choices and display an error message if the text was invalid. The program might also need to use precious screen real estate to list the choices so that the user can remember what to type.

A better idea would be to use a group of three RadioButton controls or a ComboBox with DropDownStyle set to DropDownList. Then the user can easily see the choices available and can only select a valid choice. If the program initializes the controls with a default value rather than leaving them initially undefined, it knows that there is always a valid choice selected.

The following sections summarize different categories of controls and provide some tips about when to use each.

Containing and Arranging Controls

These controls contain, group, and help arrange other controls. These controls include FlowLayoutPanel, TableLayoutPanel, GroupBox, Panel, TabControl, and SplitContainer.

The FlowLayoutPanel arranges the controls it contains in rows or columns. For example, when its FlowDirection property is LeftToRight, the control arranges its contents in rows from left to right. It positions its contents in a row until it runs out of room and then it starts a new row. FlowLayoutPanel is particularly useful for toolboxes and other situations where the goal is to display as many of the contained controls as possible at one time, and the exact arrangement of the controls isn't too important.

The TableLayoutPanel control displays its contents in a grid. All the cells in a particular row have the same height, and all the cells in a particular column have the same width. In contrast, the FlowLayoutPanel control simply places controls next to each other until it fills a row and then starts a new one. Example program LayoutPanels, which is available for download on the book's web site, is shown in Figure 8-2 displaying these two controls side by side.

FlowLayoutPanel places controls close together. TableLayoutPanel arranges controls in a grid.

Figure 8.2. FlowLayoutPanel places controls close together. TableLayoutPanel arranges controls in a grid.

A GroupBox control is good for grouping related controls or the RadioButton controls in a RadioButton group. (The RadioButton control is discussed later in this chapter in the section "Making Selections.") It provides a visible border and caption so that it can help the user make sense out of a very complicated form.

The Panel control can also contain the RadioButton controls in a RadioButton group. Unlike a GroupBox control, the Panel control doesn't display a visible border, so you must use some other method to ensure that the user can tell that the buttons form a group. For example, you could use several Panels in a row, each containing a column of RadioButton controls. Then the user would select one option from each column.

One of the Panel control's more powerful features is its ability to automatically display scroll bars. If you set a Panel control's AutoScroll property to True and the Panel resizes so all of its contents cannot fit, it automatically displays the scroll bars so the user can still see all of the content. Scrolling back and forth can be cumbersome for the user, however, so this is not the best way to display data if the user must view it all frequently. If the user must jump back and forth between different controls inside a scrolling Panel, it may be better to use a TabControl.

TabControl displays data grouped by pages. The tabs enable the user to quickly jump from page to page. The control can display scroll bars if necessary, although that makes using the control much more awkward. TabControl works well if the data falls into natural groupings that you can use for the tab pages. It doesn't work as well if the user must frequently compare values on one page with those on another, forcing the user to jump back and forth.

The SplitContainer control allows the user to divide an area between two adjacent regions. SplitContainer contains two Panel controls in which you can place your own controls. When the user drags the splitter between the two panels, the control resizes the panels accordingly. You can set the Panels' AutoScroll properties to True to make them automatically provide scroll bars when necessary.

SplitContainer is helpful when the form isn't big enough to hold all the data the program must display, and the user can trade area in one part of the form for area in another. It is particularly useful when the user must compare values in the two areas by viewing them at the same time.

Though you can nest SplitContainers inside other SplitContainers, they are easiest to use when they separate only two areas. Large groups of SplitContainers separating many areas are usually clumsy and confusing.

Example program UseSplitter, which is available for download on the book's web site, uses a Splitter control to divide its form into two regions covered by Panel controls. To make the Splitter work, the program contains a Panel with Dock = Left at the bottom of the stacking order, the Splitter next in the stacking order, and then another Panel with Dock = Fill at the top of the stacking order.

Example program UseSplitContainer, which is also available for download, uses a SplitContainer control to divide its form into two regions. The SplitContainer includes two Panel controls and a Splitter so it's all set to divide an area into two regions. Because you don't need to worry about Dock properties and stacking order as you do with a Splitter control, the SplitContainer is easier to use.

These container controls help arrange the controls they contain. The Anchor and Dock properties of any controls inside the containers work relative to the containers. For example, suppose you place a series of buttons with Anchor = Top,Left,Right inside a SplitContainer so that they are as wide as the Panel containing them. When you drag the splitter, the buttons automatically resize to fit the width of their Panel.

Making Selections

Selection controls enable the user to choose values. If you use them carefully, you can reduce the chances of the user making an invalid selection, so you can reduce the amount of error-handling code you need to write.

These controls include CheckBox, CheckedListBox, ComboBox, ListBox, RadioButton, DateTimePicker, MonthCalendar, DomainUpDown, NumericUpDown, TrackBar, HScrollBar, and VScrollBar.

CheckBox enables the user to select an option or not, independently of all other selections. If you want the user to select only one of a series of options, use a RadioButton instead. If a form requires more than, say, five to seven CheckBox controls that have related purposes, consider using a CheckedListBox instead.

The CheckedListBox control enables the user to select among several independent options. It is basically a series of CheckBox controls arranged in a list that provides scroll bars if necessary.

The ComboBox control enables the user to make one brief selection. This control is particularly useful when its DropDownStyle property is set to DropDownList because then the user must pick a value from a list. If you want to allow the user to select a value or enter one that is not on the list, set the control's DropDownStyle to Simple or DropDown. This control does roughly the same things as a simple ListBox but takes less space.

The ListBox control displays a list of items that the user can select. You can configure the control to let the user select one or more items. A ListBox takes more room than a ComboBox but can be easier to use if the list is very long.

The RadioButton control lets the user pick one of a set of options. For example, three RadioButton controls might represent the choices Small, Medium, and Large. If the user selects one, Visual Basic automatically deselects the others. This control is useful when the list of choices is relatively small, and there is a benefit to allowing the user to see all the choices at the same time. If the list of choices is long, consider using a ListBox or ComboBox.

The DateTimePicker and MonthCalendar controls enable the user to select dates and times. They validate the user's selections, so they are generally better than other controls for selecting dates and times. For example, if you use a TextBox to let the user enter month, date, and year, you must write extra validation code to ensure that the user doesn't enter February 29, 2013.

The DomainUpDown and NumericUpDown controls let the user scroll through a list of values. If the list is relatively short, a ListBox or ComboBox may be easier for the user. The DomainUpDown and NumericUpDown controls take very little space, however, so they may be helpful on very crowded forms. By holding down one of the controls' arrow buttons, the user can scroll very quickly through the values, so these controls can also be useful when they represent a long list of choices.

The TrackBar control lets the user drag a pointer to select an integer value. This is usually a more intuitive way to select a value than a NumericUpDown control, although it takes a lot more space on the form. It also requires some dexterity if the range of values allowed is large.

The HScrollBar and VScrollBar controls let the user drag a "thumb" across a bar to select an integral value much as the TrackBar does. HScrollBar, VScrollBar, and TrackBar even have similar properties. The main difference is in the controls' appearances. On one hand, the two scroll bar controls allow more flexible sizing (the TrackBar has definite ideas about how tall it should be for a given width), and they may seem more elegant to some users. On the other hand, users are familiar with the scroll bars' normal purpose of scrolling an area on the form, so using them as numeric selection bars may sometimes be confusing.

Entering Data

Sometimes it is impractical to use the selection controls described in the previous section. For example, the user cannot reasonably enter a long work history or comments using a ComboBox or RadioButton.

The RichTextBox, TextBox, and MaskedTextBox controls let the user enter text with few restrictions. These controls are most useful when the user must enter a large amount of textual data that doesn't require any validation.

The TextBox control is less complex and easier to use than the RichTextBox control, so you may want to use it unless you need the RichTextBox control's extra features. If you need those features (such as multiple fonts, indentation, paragraph alignment, superscripting and subscripting, multiple colors, more than one level of undo/redo, and so forth), you need to use a RichTextBox.

The MaskedTextBox control is a TextBox control that requires the user to enter data in a particular format. For example, it can help the user enter a phone number of the form 234-567-8901. This is useful only for short fields where the format is tightly constrained. In those cases, however, it reduces the chances of the user making mistakes.

Displaying Data

These controls display data to the user: Label, DataGridView, ListView, TreeView, and PropertyGrid.

The Label control displays a simple piece of text that the user can view but not select or modify. Because you cannot select the text, you cannot copy it to the clipboard. If the text contains a value that you think the user might want to copy to the clipboard and paste into another application (for example, serial numbers, phone numbers, e-mail addresses, web URLs, and so forth), you can use a TextBox control with its ReadOnly property set to True to allow the user to select and copy the text.

The DataGridView control can display table-like data. The control can also display several tables linked with master/detail relationships and the user can quickly navigate through the data. You can also configure this control to allow the user to update the data.

The ListView control displays data that is naturally viewed as a series of icons or as a list of values with columns providing extra detail. With a little extra work, you can sort the data by item or by detail columns.

The TreeView control displays hierarchical data in a tree-like format similar to the directory display provided by Windows Explorer. You can determine whether the control allows the user to edit the nodes' labels.

The PropertyGrid control displays information about an object in a format similar to the one used by the Properties window at design time. The control enables the user to organize the properties alphabetically or by category and lets the user edit the property values. Example program EmployeePropertyGrid, which is available for download on the book's web site, is shown in Figure 8-3 displaying information about an Employee object in a PropertyGrid control.

The PropertyGrid control displays an object's properties.

Figure 8.3. The PropertyGrid control displays an object's properties.

Providing Feedback

These controls provide feedback to the user: ToolTip, HelpProvider, ErrorProvider, NotifyIcon, StatusStrip, and ProgressBar. Their general goal is to tell the user what is going on without becoming so obtrusive that the user cannot continue doing other things. For example, the ErrorProvider flags a field as incorrect but doesn't prevent the user from continuing to enter data in other fields.

The ToolTip control provides the user with a brief hint about a control's purpose when the user hovers the mouse over it. The HelpProvider gives the user more detailed help about a control's purpose when the user sets focus to the control and presses F1. A high-quality application provides both tooltips and F1 help for every control. These features are unobtrusive and appear only if the user needs them, so it is better to err on the side of providing too much help rather than not enough.

The NotifyIcon control can display a small icon in the taskbar notification area to let the user easily learn the application's status. This is particularly useful for applications that run in the background without the user's constant attention. If the application needs immediate action from the user, it should display a dialog or message box rather than relying on a NotifyIcon.

The StatusStrip control displays an area (usually at the bottom of the form) where the program can give the user some information about its state. This information can be in the form of small images or short text messages. It can contain a lot more information than a NotifyIcon, although it is visible only when the form is displayed.

The ProgressBar indicates how much of a long task has been completed. Usually, the task is performed synchronously, so the user is left staring at the form while it completes. The ProgressBar lets the user know that the operation is not stuck.

Initiating Action

Every kind of control responds to events, so every control can initiate an action. Nevertheless, users only expect certain kinds of controls to perform significant actions. For example, users expect pushing a button to start an action, but they don't expect clicking a label or check box to start a long process.

To prevent confusion, you should start actions from the controls most often used to start actions. These controls include Button, MenuStrip, ContextMenuStrip, ToolStrip, LinkLabel, TrackBar, HScrollBar, VScrollBar, and Timer. All except the Timer control let the user initiate the action.

All of these controls interact with the program through event handlers. For example, the Button control's Click event handler normally makes the program perform some action when the user clicks the button.

Other controls also provide events that can initiate action. For example, the CheckBox control provides CheckChanged and Click events that you could use to perform some action. By catching the proper events, you can use almost any control to initiate an action. Because the main intent of those controls is not to execute code, they are not listed in this section.

The Button control allows the user to tell the program to execute a particular function. A button is normally always visible on its form, so it is most useful when the user must perform the action frequently or the action is part of the program's central purpose. For actions less frequently performed, use a MenuStrip or ContextMenuStrip control.

Items in a MenuStrip control also enable the user to make the program perform an action. You must perform more steps to open the menu, find the item, and select it than you must to click a button, so a Button control is faster and easier. On the other hand, menus take up less form real estate than buttons. You can also assign keyboard shortcuts (such as F5 or Ctrl+S) to frequently used menu items, making them even easier to invoke than buttons.

A ContextMenuStrip control provides the same advantages and disadvantages as a MenuStrip control. ContextMenuStrip is available only from certain controls on the form, however, so it is useful for commands that are appropriate only within specific contexts. For example, a Save command applies to all the data loaded by a program, so it makes sense to put it in a MenuStrip. A command that deletes a particular object in a drawing only applies to that object. By placing the command in a ContextMenuStrip control attached to the object, the program keeps the command hidden when the user is working on other things. It also makes the relationship between the action (delete) and the object clear to both the user and the program.

The ToolStrip control combines some of the best features of menus and buttons. It displays a series of buttons so they are easy to use without navigating through a menu. The buttons are small and grouped at the top of the form, so they don't take up as much space as a series of larger buttons.

It is common to place buttons or ToolStrip buttons on a form to duplicate frequently used menu commands. The menu commands provide keyboard shortcuts for more advanced users, and the buttons make it easy to invoke the commands for less-experienced users.

The LinkLabel control displays text much as a Label control does. It also displays some text in blue with an underline, displays a special cursor when the user moves over that text, and raises an event if the user clicks the text. That makes the control appropriate when clicking a piece of text should perform some action. For example, on a web page, clicking a link typically navigates to the link's web page.

The TrackBar, HScrollBar, and VScrollBar controls let the user drag a "thumb" across a bar to select an integral value. As mentioned in the section "Making Selections" earlier in this chapter, you can use these controls to let the user select a numeric value. However, they can also be used to perform some action interactively. For example, the scroll bars are often used to scroll an area on the form. More generally, they are used to make the program take action based on some new value. For example, you could use a scroll bar to let the user select new red, green, and blue color components for an image. As the user changed a scroll bar's value, the program would update the image's colors.

The Timer control triggers some action at a regular interval. When the Timer control raises its Timer event, the program takes action.

Displaying Graphics

These controls display graphics, either on the screen or on a printout: Form, PictureBox, PrintPreviewControl, PrintDocument, and PrintPreviewDialog.

A Form (which can also display graphics) provides methods for drawing, but it's often better to draw in a PictureBox control instead of the form itself. That makes it easier to move the drawing if you later need to redesign the form. For example, if you decide that the picture might be too big, it is easy to move a PictureBox control into a scrolling Panel control. It would be much harder to rewrite the code to move the drawing from the Form into a PictureBox control later.

PrintPreviewControl displays a print preview for a PrintDocument object. The program responds to events raised by the PrintDocument object. PrintPreviewControl displays the results within a control on one of the program's forms.

The PrintPreviewDialog control displays graphics from a PrintDocument object much as a PrintPreviewControl does, but it provides its own dialog box. Unless you need to arrange the print preview in some special way, it is easier to use a PrintPreviewDialog rather than build your own preview dialog box with a PrintPreviewControl. The PrintPreviewDialog control provides many features that enable the user to zoom, scroll, and move through the pages of the preview document. Implementing those features yourself would be a lot of work.

Displaying Dialog Boxes

Visual Basic provides a rich assortment of dialog boxes that enable the user to make standard selections. Figuring out which of these dialog boxes to use is usually easy because each has a very specific purpose. The following table lists the dialog boxes and their purposes.

DIALOG

PURPOSE

ColorDialog

Select a color.

FolderBrowserDialog

Select a folder (directory).

FontDialog

Select a font.

OpenFileDialog

Select a file to open.

PageSetupDialog

Specify page set up for printing.

PrintDialog

Print a document.

PrintPreviewDialog

Display a print preview.

SaveFileDialog

Select a file for saving.

Example program UseDialogs, which is available for download on the book's web site, demonstrates each of these dialogs.

Supporting Other Controls

Many of the Visual Basic controls require the support of other controls. The two controls used most by other controls are ImageList and PrintDocument. These controls also include DataConnector and DataNavigator.

The ImageList control holds images for other controls to display. Your code can also take images from an ImageList control to use in whatever way it needs.

The PrintDocument control provides support for printing and print previewing. It generates the graphics sent to the printer, PrintPreviewDialog, or PrintPreviewControl.

The DataConnector control provides a link between a data source and controls bound to the connector. The program can use the DataConnector's methods to navigate, sort, filter, and update the data, and the control updates its bound controls appropriately.

The DataNavigator control provides methods for navigating through a data source such as DataConnector.

THIRD-PARTY CONTROLS

Visual Basic comes with a large number of useful controls ready to go, but many other controls are available that you can use if you need them. If you right-click the Toolbox and select Choose Items, you can select from a huge list of .NET Framework and COM components available on your system.

You can also obtain other controls provided by other companies and available for purchase and sometimes for free on the Web. Many of these controls perform specialized tasks such as generating bar codes, making shaped forms, warping images, and providing special graphical effects.

Other controls extend the standard controls to provide more power or flexibility. Several controls are available that draw two- and three-dimensional charts and graphs. Other controls provide more powerful reporting services than those provided by Visual Studio's own tools.

If you use any major web search engine to search for "windows forms controls," you will find lots of web sites where you can download controls for free or for a fee. A few places you might like to explore include:

  • MVPs.org (www.mvps.org), a site leading to resources provided by people related to Microsoft's Most Valuable Professional (MVP) program. The Common Controls Replacement Project (ccrp.mvps.org) provides controls that duplicate and enhance standard Visual Basic 6 controls. Development on this project has stopped but some of the old Visual Basic 6 controls may give you some ideas for building controls of your own. MVPs.org is also a good general resource.

  • Windows Forms .NET (windowsclient.net), Microsoft's official WPF and Windows Forms .NET community.

  • ASP.NET (www.asp.net), Microsoft's official ASP.NET community.

  • Download.com (www.download.com).

  • Shareware.com (www.shareware.com).

  • Shareware Connection (www.sharewareconnection.com).

You should use these as a starting point for your own search, not as a definitive list. You can download controls from hundreds (if not thousands) of web sites.

SUMMARY

Controls form the main connection between the user and the application. They allow the application to give information to the user, and they allow the user to control the application. Controls are everywhere in practically every Windows application. Only a tiny percentage of applications that run completely in the background can do without controls.

This chapter briefly describes purposes of the standard Visual Basic controls and provides a few tips for selecting the controls appropriate for different purposes. Appendix G describes the controls in much greater detail.

Even knowing all about the controls doesn't guarantee that you can produce an adequate user interface. There's a whole science to designing user interfaces that are intuitive and easy to use. A good design enables the user to get a job done naturally and with a minimum of wasted work. A bad interface can encumber the user and turn even a simple job into an exercise in beating the application into submission.

For more information on building usable applications, read some books on user-interface design. They explain standard interface issues and solutions. You can also learn a lot by studying other successful applications. Look at the layout of their forms and dialog boxes. You shouldn't steal their designs outright, but you can try to understand why they arrange their controls in the way they do. Look at applications that you like and find particularly easy to use. Compare them with applications that you find awkward and confusing.

This chapter provided an introduction to Windows Forms controls to help you decide which controls to use for different purposes. Chapter 9, "Using Windows Forms Controls," explains in greater detail how you can use the controls you select. It tells how to add a control to a form at design time or runtime, and explains how to use a control's properties, methods, and events.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.47.230