Available Windows Forms Controls

In Chapter 4, you looked at some of the differences between the ActiveX controls in VBA and the equivalent Windows Forms controls. Table 8.1 lists all the Windows Forms controls that appear on the Toolbox when a Windows Form has focus and when the document has focus (DesignTime Support in Document). The table includes a short description of each control, but this book does not go into detail about each control's properties and events. We encourage you to explore the VSTO documentation to learn more about the members of these controls.

Table 8.1. Additional Windows Form Controls

Control

Description

Design-Time Support in Document

BackgroundWorker

Component that enables you to run an operation in the background (asynchronously) by running it on a separate thread. This is useful when an operation typically takes a long time. The default event handler is DoWork.

Y

BindingNavigator

Component that enables you to navigate through data that is bound to another control. This creates both a UI for the Form and a component on the component tray. The default event handler is RefreshItems.

(continues)

Table 8.1. Additional Windows Form Controls (Continued)

Control

Description

Design-Time Support in Document

BindingSource

Component that indirectly binds a data source to a control. Instead of binding the control directly to the data source, you bind the control to the BindingSource, which is then bound to the data source. The default event handler is CurrentChanged.

Y

Button

Provides a control that can perform an action when the user clicks it. The default event handler is Click.

Y

CheckBox

Displays an on/off or true/false status. This can also be used to create a ToggleButton if you change the Appearance property to Button. The default event handler is CheckChanged.

Y

CheckedListBox

Displays a list that contains check boxes for each item in the list. The default event handler is SelectedIndexChanged.

Y

ColorDialog

Component that enables you to display a color palette in a dialog box from which users can select a color.

Y

ComboBox

Provides a control with a drop-down arrow from which users can select an item. The default event handler is SelectedIndexChanged.

Y

Table 8.1. Additional Windows Form Controls (Continued)

Control

Description

Design-Time Support in Document

ContextMenuStrip

Component that provides a context menu (shortcut menu) for another control. This creates both a UI for the form and a component on the component tray. The default event handler is Opening.

N

DataGridView

Provides a grid for displaying data in a table. The default event handler is CellContentClick.

Y

DataSet

Component that enables you to add a typed or untyped dataset to a Windows Form.

Y

DateTimePicker

Provides a drop-down calendar from which users can select a single date and time. The default event handler is ValueChanged.

Y

DirectoryEntry

Component that enables you to access objects within the Active Directory hierarchy.

N

DirectorySearcher

Component that enables you to run queries against an Active Directory hierarchy.

N

DomainUpDown

Combines a text box with a pair of buttons that you can use to navigate up and down a list of items. The default event handler is SelectedItemChanged.

Y

ErrorProvider

Component that displays information to users about validation errors that exist on corresponding controls.

N

Table 8.1. Additional Windows Form Controls (Continued)

Control

Description

Design-Time Support in Document

EventLog

Component that enables you to read from and write to Windows event logs. The default event handler is EntryWritten.

N

FileSystemWatcher

Component that enables you to capture events when changes occur to a directory or its files. The default event handler is Changed.

N

FlowLayoutPanel

Enables you to create a horizontal or vertical layout flow for the content in the FlowLayoutPanel. The default event handler is Paint.

N

FolderBrowseDialog

Component that displays a dialog box that enables users to browse to a folder or create a new one.

Y

FontDialog

Component that displays a dialog box that contains all fonts that are currently installed on the system. The default event handler is Apply.

Y

GroupBox

Provides a way to group controls and isolate them from other controls on the form. For example, if you want to make option buttons mutually exclusive, you can place them in a GroupBox control. The default event handler is Enter.

N

HelpProvider

Component that associates an application with an HTML Help file.

Y

372

Chapter 8 Controls in Word and Excel

Table 8.1. Additional Windows Form Controls (Continued)

Control

Description

Design-Time Support in Document

HScrollBar

Enables horizontal scrolling for another control. Most controls that require scrolling provide this functionality natively. The default event handler for this control is Scroll.

Y

ImageList

Component that displays a list of images that can be used on other controls. Click the Images property to display the Image Collection Editor, where you can add or modify images in the list.

Y

Label

A read-only control for displaying information. This control is typically used to label other controls on the Windows Form or document. The default event handler is Click.

Y

LinkLabel

Enables you to add Web-style links to a Windows Form. The default event handler is LinkClicked.

Y

ListBox

Contains multiple items from which a user can select. The default event handler is SelectedIndexChanged.

Y

ListView

Displays a list of items with associated icons in a hierarchical folder structure similar to the one in the left pane of Windows Explorer. The default event handler is SelectedIndexChanged.

Y

Table 8.1. Additional Windows Form Controls (Continued)

Control

Description

Design-Time Support in Document

MaskedTextBox

Component that constrains the format of user input. The default event handler is MaskInputRejected.

Y

MenuStrip

Provides a menu system on a Windows Form. This creates both a UI for the form and a component on the component tray. The default event handler is ItemClicked.

N

MessageQueue

Component that provides a way to access a queue on a MessageQueue server.

N

MonthCalendar

Contains a calendar from which users can select a date or range of dates. The default event handler is DateChanged.

Y

NotifyIcon

Component that displays icons in the status bar for background processes that do not have a user interface. The default event handler is MouseDoubleClick.

N

NumericUpDown

Combines a text box with a pair of buttons that you can use to navigate up and down a list of numbers. The default event handler is ValueChanged.

Y

OpenFileDialog

Component that displays a dialog box that enables users to select and open files. The default event handler is FileOK.

Y

Table 8.1. Additional Windows Form Controls (Continued)

Control

Description

Design-Time Support in Document

PageSetupDialog

Component that displays a dialog box that enables users to set page details for printing.

N

Panel

Provides a way to group other controls and can contain a scroll bar. The default event handler is Paint.

N

PerformanceCounter

Component that collects or publishes performance data.

N

PictureBox

Displays images on a Windows Form or document. The default event handler is Click.

Y

PrintDialog

Component that displays a dialog box where users can select a printer and print a document.

N

PrintDocument

Component that enables users to select print options and then print a document. The default event handler is PrintPage.

N

PrintPreviewControl

Enables you to create your own component for previewing a document.

N

PrintPreviewDialog

Component that displays a dialog box where you can display a document as it will appear when it is printed. The default event handler is Click.

N

Process

Component that gives you access to local and remote processes. The default event handler is Exited.

N

Table 8.1. Additional Windows Form Controls (Continued)

Control

Description

Design-Time Support in Document

ProgressBar

Displays the progress of an action in a horizontal bar. The default event handler is Click.

Y

PropertyGrid

Displays the properties of another control. The default event handler is Click.

Y

RadioButton

Displays a true/false status. You can make multiple RadioButtons mutually exclusive (only one control in the group can have its value set to True) by adding them to a GroupBox control. For documents, GroupBox controls are not supported, so you must use a custom user control in order to make RadioButton controls on a document mutually exclusive. This control is equivalent to an OptionButton, and the default event handler is CheckChanged.

Y

ReportViewer

Displays reports in a Windows Form. The default event handler is Load.

N

RichTextBox

Displays text in a text box that can contain formatting. The default event handler is TextChanged.

N

SaveFileDialog

Component that displays a dialog box where users can save a file to a particular location. The default event handler is FileOK.

Y

Table 8.1. Additional Windows Form Controls (Continued)

Control

Description

Design-Time Support in Document

SerialPort

Component that gives you access to serial port data.

N

ServiceController

Component that gives you access to a Windows service, whether it is running or stopped.

N

SplitContainer

Divides a container into two areas that can be resized.

N

Splitter

Enables users to resize a control that is docked. Use SplitContainer instead.

N

StatusStrip

Component that represents a status bar. This creates both a UI for the form and a component on the component tray. The default event handler is ItemClicked.

N

TabControl

Displays controls on different tabs. This control is often used to save screen real estate, and it is handy for use on the actions pane. The default event handler is Click.

N

TableLayoutPanel

Represents a panel that can display its controls in a table format. The default event handler is Paint.

N

TextBox

Collects input from users. The default event handler is TextChanged.

Y

Timer

Component that raises events at regular intervals. The default event handler is Tick.

N

Table 8.1. Additional Windows Form Controls (Continued)

Control

Description

Design-Time Support in Document

ToolStrip

Component that creates a custom toolbar or menu in a Windows Form. This both creates a UI for the form and adds a component to the component tray. The default event handler is ItemClicked.

N

ToolStripContainer

Provides a panel on each side of a form that contains a ToolStrip control.

N

ToolTip

Component that displays text when a user holds the cursor over other controls. The default event handler is Popup.

Y

TrackBar

Enables navigation through information via a slider that moves in increments. The default event handler is Scroll.

N

TreeView

Displays nodes that are arranged hierarchically and can be expanded and collapsed. The default event handler is AfterSelect.

Y

VScrollBar

Enables vertical scrolling for another control. Most controls that require scrolling provide this functionality natively. The default event handler is Scroll.

Y

WebBrowser

Enables you to host Web pages that have browsing capabilities on a Windows Form. The default event handler is DocumentCompleted.

Y

In addition to visible controls, there are a number of controls known as components. Components do not have a user interface; instead, when you drag one to a Windows Form or a document, they appear in an area beneath the visual designer called the component tray. For example, if you drag an ImageList control to your document, it appears in the component tray rather than the document, and you can select the control to set its properties in the Properties window.

You can also add controls to the Toolbox, including third-party controls. For example, if you create a user control and compile your project, the control is added to the Toolbox. You can then drag the user control from the Toolbox to your document. This feature can come in handy when you want to use the functionality of controls that are not available in the Toolbox.

For example, container controls cannot be added to a document at design time because VSTO does not support adding Windows Forms controls within another Windows Form control. This means that you cannot add a control, such as a group box, to the document and then add radio buttons or check boxes to the group box as a way of making the controls mutually exclusive. But you can add the radio buttons to a group box on a user control and then add the user control to the document. For an example of how you can implement this with a custom user control, see the section "Adding Controls to Documents" later in this chapter. First, we look at adding controls to a Windows Form.

0 0

Post a comment