Bewerken

Delen via


Overview of using controls (Windows Forms .NET)

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. For more information, see Types of custom controls.

Adding controls

Controls are added through the Visual Studio Designer. With the Designer, you can place, size, align, and move controls. Alternatively, controls can be added through code. For more information, see Add a control (Windows Forms).

Layout options

The position a control appears on a parent is determined by the value of the Location property relative to the top-left of the parent surface. The top-left position coordinate in the parent is (x0,y0). The size of the control is determined by the Size property and represents the width and height of the control.

Besides manual positioning and sizing, various container controls are provided that help with automatic placement of controls.

For more information, see Position and layout of controls and How to dock and anchor controls.

Control events

Controls provides more than 60 events through the base class Control. These include the Paint event, which causes a control to be drawn, events related to displaying a window, such as the Resize and Layout events, and low-level mouse and keyboard events. Some low-level events are synthesized by Control into semantic events such as Click and DoubleClick. Most shared events fall under these categories:

  • Mouse events
  • Keyboard events
  • Property changed events
  • Other events

Not every control responds to every event. For example, the Label control doesn't respond to keyboard input, and the Control.PreviewKeyDown event isn't raised.

Often, a control is a wrapper for an underlaying Win32 control, and using the Paint event to draw on top of the control may be limited or do nothing at all, since the control is ultimately drawn by Windows.

For more information, see Control events and How to handle a control event.

Control accessibility

Windows Forms has accessibility support for screen readers and voice input utilities for verbal commands. However, you must design your UI with accessibility in mind. Windows Forms controls expose various properties to handle accessibility. For more information about these properties, see Providing Accessibility Information for Controls.

See also