Developing Custom Windows Forms Controls with the .NET Framework
Windows Forms controls are reusable components that encapsulate user interface functionality and are used in client-side Windows-based applications. Not only does Windows Forms provide many ready-to-use controls, it also provides the infrastructure for developing your own controls. You can combine existing controls, extend existing controls, or author your own custom controls. This section provides background information and samples to help you develop Windows Forms controls.
In This Section
Overview of Using Controls in Windows Forms
Highlights the essential elements of using controls in Windows Forms applications.
Varieties of Custom Controls
Describes the different kinds of custom controls you can author with the System.Windows.Forms namespace.
Windows Forms Control Development Basics
Discusses the first steps in developing a Windows Forms control.
Properties in Windows Forms Controls
Shows how to add to properties to Windows Forms controls.
Events in Windows Forms Controls
Shows how to handle and define events in Windows Forms controls.
Attributes in Windows Forms Controls
Describes the attributes you can apply to properties or other members of your custom controls and components.
Custom Control Painting and Rendering
Shows how to customize the appearance of your controls.
Layout in Windows Forms Controls
Shows how to create sophisticated layouts for your controls and forms.
Multithreading in Windows Forms Controls
Shows how to implement multithreaded controls.
Reference
System.Windows.Forms.Control
Describes this class and has links to all of its members.
System.Windows.Forms.UserControl
Describes this class and has links to all of its members.
Related Sections
Design-Time Attributes for Components
Lists metadata attributes to apply to components and controls so that they are displayed correctly at design time in visual designers.
Extending Design-Time Support
Describes how to implement classes such as editors and designers that provide design-time support.
How to: License Components and Controls
Describes how to implement licensing in your control or component.
Controls to Use on Windows Forms
The following is an alphabetic list of controls and components that can be used on Windows Forms. In addition to the Windows Forms controls covered in this section, you can add ActiveX and custom controls to Windows Forms. If you do not find the control you need listed here, you can also create your own. For details, see Developing Windows Forms Controls at Design Time. For more information about choosing the control you need, see Windows Forms Controls by Function.
Visual Basic controls are based on classes provided by the .NET Framework.
In This Section
Windows Forms Controls by Function
Lists and describes Windows Forms controls based on the .NET Framework.
Controls with Built-In Owner-Drawing Support
Describes how to alter aspects of a control’s appearance that are not available through properties.
BackgroundWorker Component
Enables a form or control to run an operation asynchronously.
BindingNavigator Control
Provides the navigation and manipulation user interface (UI) for controls that are bound to data.
BindingSource Component
Encapsulates a data source for binding to controls.
Button Control
Presents a standard button that the user can click to perform actions.
CheckBox Control
Indicates whether a condition is on or off.
CheckedListBox Control
Displays a list of items with a check box next to each item.
ColorDialog Component
Allows the user to select a color from a palette in a pre-configured dialog box and to add custom colors to that palette.
ComboBox Control
Displays data in a drop-down combo box.
ContextMenu Component
Provides users with an easily accessible menu of frequently used commands that are associated with the selected object. Although ContextMenuStrip replaces and adds functionality to the ContextMenu control of previous versions, ContextMenu is retained for both backward compatibility and future use if so desired.
ContextMenuStrip Control
Represents a shortcut menu. Although ContextMenuStrip replaces and adds functionality to the ContextMenu control of previous versions, ContextMenu is retained for both backward compatibility and future use if so desired.
DataGrid Control
Displays tabular data from a dataset and allows for updates to the data source.
DataGridView Control
Provides a flexible, extensible system for displaying and editing tabular data.
DateTimePicker Control
Allows the user to select a single item from a list of dates or times.
Dialog-Box Controls and Components
Describes a set of controls that allow users to perform standard interactions with the application or system.
DomainUpDown Control
Displays text strings that a user can browse through and select from.
ErrorProvider Component
Displays error information to the user in a non-intrusive way.
FileDialog Class Provides base-class functionality for file dialog boxes.
FlowLayoutPanel Control
Represents a panel that dynamically lays out its contents horizontally or vertically.
FolderBrowserDialog Component
Displays an interface with which users can browse and select a directory or create a new one.
FontDialog Component
Exposes the fonts that are currently installed on the system.
GroupBox Control
Provides an identifiable grouping for other controls.
HelpProvider Component
Associates an HTML Help file with a Windows-based application.
HScrollBar and VScrollBar Controls
Provide navigation through a list of items or a large amount of information by scrolling either horizontally or vertically within an application or control.
ImageList Component
Displays images on other controls.
Label Control
Displays text that cannot be edited by the user.
LinkLabel Control
Allows you to add Web-style links to Windows Forms applications.
ListBox Control
Allows the user to select one or more items from a predefined list.
ListView Control
Displays a list of items with icons, in the manner of Windows Explorer.
MainMenu Component
Displays a menu at run time. Although MenuStrip replaces and adds functionality to the MainMenu control of previous versions, MainMenu is retained for both backward compatibility and future use if you choose.
MaskedTextBox Control
Constrains the format of user input in a form.
MenuStrip Control
Provides a menu system for a form. Although MenuStrip replaces and adds functionality to the MainMenu control of previous versions, MainMenu is retained for both backward compatibility and future use if you choose.
MonthCalendar Control
Presents an intuitive graphical interface for users to view and set date information.
NotifyIcon Component
Displays icons for processes that run in the background and would not otherwise have user interfaces.
NumericUpDown Control
Displays numerals that a user can browse through and select from.
OpenFileDialog Component
Allows users to open files by using a pre-configured dialog box.
PageSetupDialog Component
Sets page details for printing through a pre-configured dialog box.
Panel Control
Provide an identifiable grouping for other controls, and allows for scrolling.
PictureBox Control
Displays graphics in bitmap, GIF, JPEG, metafile, or icon format.
PrintDialog Component
Selects a printer, chooses the pages to print, and determines other print-related settings.
PrintDocument Component
Sets the properties that describe what to print, and prints the document in Windows-based applications.
PrintPreviewControl Control
Allows you to create your own PrintPreview component or dialog box instead of using the pre-configured version.
PrintPreviewDialog Control
Displays a document as it will appear when it is printed.
ProgressBar Control
Graphically indicates the progress of an action towards completion.
RadioButton Control
Presents a set of two or more mutually exclusive options to the user.
RichTextBox Control
Allows users to enter, display, and manipulate text with formatting.
SaveFileDialog Component
Selects files to save and where to save them.
SoundPlayer Class Enables you to easily include sounds in your applications.
SplitContainer Control
Allows the user to resize a docked control.
Splitter Control
Allows the user to resize a docked control (.NET Framework version 1.x).
StatusBar Control
Displays status information related to the control that has focus. Although StatusStrip replaces and extends the StatusBar control of previous versions, StatusBar is retained for both backward compatibility and future use if you choose.
StatusStrip Control
Represents a Windows status bar control. Although StatusStrip replaces and extends the StatusBar control of previous versions, StatusBar is retained for both backward compatibility and future use if you choose.
TabControl Control
Displays multiple tabs that can contain pictures or other controls.
TableLayoutPanel Control
Represents a panel that dynamically lays out its contents in a grid composed of rows and columns.
TextBox Control
Allows editable, multiline input from the user.
Timer Component
Raises an event at regular intervals.
ToolBar Control
Displays menus and bitmapped buttons that activate commands. You can extend the functionality of the control and modify its appearance and behavior. Although ToolStrip replaces and adds functionality to the ToolBar control of previous versions, ToolBar is retained for both backward compatibility and future use if you choose.
ToolStrip Control
Creates custom toolbars and menus in your Windows Forms applications. Although ToolStrip replaces and adds functionality to the ToolBar control of previous versions, ToolBar is retained for both backward compatibility and future use if you choose.
ToolStripContainer Control
Provides panels on each side of a form for docking, rafting, and arranging ToolStrip controls, and a central ToolStripContentPanel for traditional controls.
ToolStripPanel Control
Provides one panel for docking, rafting and arranging ToolStrip controls.
ToolStripProgressBar Control Overview
Graphically indicates the progress of an action towards completion. The ToolStripProgressBar is typically contained in a StatusStrip.
ToolTip Component
Displays text when the user points at other controls.
TrackBar Control
Allows navigation through a large amount of information or visually adjusting a numeric setting.
TreeView Control
Displays a hierarchy of nodes that can be expanded or collapsed.
WebBrowser Control
Hosts Web pages and provides Internet Web browsing capabilities to your application.
Windows Forms Controls Used to List Options
Describes a set of controls used to provide users with a list of options to choose from.
Related Sections
Windows Forms Controls
Explains the use of Windows Forms controls, and describes important concepts for working with them.
Developing Windows Forms Controls at Design Time
Provides links to step-by-step topics, recommendations for which kind of control to create, and other information about creating your own control.
Controls and Programmable Objects Compared in Various Languages and Libraries
Provides a table that maps controls in Visual Basic 6.0 to the corresponding control in Visual Basic .NET. Note that controls are now classes in the .NET Framework.
How to: Add ActiveX Controls to Windows Forms
Describes how to use ActiveX controls on Windows Forms.
Control. Controls Свойство
Определение
Возвращает коллекцию элементов управления, содержащихся в элементе управления. Gets the collection of controls contained within the control.
Значение свойства
Объект Control.ControlCollection представляет коллекцию элементов управления, содержащихся в элементе управления. A Control.ControlCollection representing the collection of controls contained within the control.
Примеры
В следующем примере кода удаляется Control из Control.ControlCollection производного класса, Panel если он является членом коллекции. The following code example removes a Control from the Control.ControlCollection of the derived class Panel if it is a member of the collection. В этом примере необходимо создать, Panel Button и хотя бы один RadioButton элемент управления в Form . The example requires that you have created a Panel, a Button, and at least one RadioButton control on a Form. RadioButtonЭлементы управления добавляются в Panel элемент управления, а Panel элемент управления добавляется в Form . The RadioButton control(s) are added to the Panel control, and the Panel control added to the Form. При нажатии кнопки переключатель removeButton удаляется из Control.ControlCollection . When the button is clicked, the radio button named removeButton is removed from the Control.ControlCollection.
Комментарии
ControlМожет действовать как родительская коллекция элементов управления. A Control can act as a parent to a collection of controls. Например, при добавлении нескольких элементов управления в Form каждый из элементов управления является членом объекта, Control.ControlCollection присвоенного Controls свойству формы, который является производным от Control класса. For example, when several controls are added to a Form, each of the controls is a member of the Control.ControlCollection assigned to the Controls property of the form, which is derived from the Control class.
Управлять элементами управления в Control.ControlCollection назначенном Controls свойстве можно с помощью методов, доступных в Control.ControlCollection классе. You can manipulate the controls in the Control.ControlCollection assigned to the Controls property by using the methods available in the Control.ControlCollection class.
При добавлении нескольких элементов управления в родительский элемент управления рекомендуется вызывать SuspendLayout метод перед инициализацией добавляемых элементов управления. When adding several controls to a parent control, it is recommended that you call the SuspendLayout method before initializing the controls to be added. После добавления элементов управления в родительский элемент управления вызовите ResumeLayout метод. After adding the controls to the parent control, call the ResumeLayout method. Это повысит производительность приложений с большим количеством элементов управления. Doing so will increase the performance of applications with many controls.
Используйте Controls свойство для прохода по всем элементам управления формы, включая вложенные элементы управления. Use the Controls property to iterate through all controls of a form, including nested controls. Используйте GetNextControl метод для получения предыдущего или следующего дочернего элемента управления в последовательности табуляции. Use the GetNextControl method to retrieve the previous or next child control in the tab order. Используйте ActiveControl свойство, чтобы получить или задать активный элемент управления контейнера. Use the ActiveControl property to get or set the active control of a container control.