Button Classes

If labels are the most common control in Windows applications, then buttons must be a close second. A command button tells the application to take some action. In the .NET Framework, the Button control is an instance of the System.Windows.Forms.Button class. It, along with the CheckBox and RadioButton controls, are derived from the ButtonBase class, as shown in Figure 11-4. The CheckBox and RadioButton controls are covered in the next section.

Button class hierarchy

Figure 11-4. Button class hierarchy

The ButtonBase class has several commonly used properties listed in Table 11-9, in addition to those inherited from Control. The ImageList and ImageIndex properties were demonstrated in Section 7.1.2.15. Other common ButtonBase properties will be demonstrated with a Button control in Example 11-5 and Example 11-6.

Table 11-9. ButtonBase properties

Property

Value type

Description

FlatStyle

FlatStyle

Read/write. The flat-style appearance of the control. Valid values must be a member of the FlatStyle enumeration, listed in Table 11-10. The default value is FlatStyle.Standard.

Image

Image

Read/write. The image displayed on the control. Cannot be used for the same control at the same time as the ImageList or ImageIndex properties.

ImageAlign

ContentAlignment

Read/write. Aligns image displayed in the label. Values are members of the ContentAlignment enumeration, listed in Table 11-3. The ...

Get Programming .NET Windows Applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.