Chapter 9: Introduction to Windows Forms Controls


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), control the application (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 and some tips that can help you decide which control to use for different purposes. Appendix G covers the controls in much greater detail, describing each control’s most useful properties, methods, and events.

Figure 9-1 shows the Visual Basic toolbox displaying the standard Windows forms controls.

image from book
Figure 9-1: Visual Basic provides a large number of standard controls for Windows forms.

Controls Overview

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

Open table as spreadsheet

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.

ReportViewer

Displays a report generated either locally or remotely on a report server. Remote processing requires Microsoft SQL Server 2005 report server.

Row 6

 

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.

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.

Row 7

 

Timer

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

ToolStrip

Displays a series of buttons, drop-downs, 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, treelike 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.

See Appendix G for detailed descriptions of the controls.




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net