Читати англійською Редагувати

Поділитися через


ButtonBase.Image Property

Definition

Gets or sets the image that is displayed on a button control.

C#
public System.Drawing.Image Image { get; set; }
C#
public System.Drawing.Image? Image { get; set; }

Property Value

The Image displayed on the button control. The default value is null.

Examples

The following code example uses the derived class, Button and sets some of its common properties. The result will be a flat button with text on the left and an image on the right. This code requires that you have a bitmap image named MyBitMap.bmp stored in the C:\Graphics directory, and that a reference to the System.Drawing namespace is included.

C#
private void SetMyButtonProperties()
 {
    // Assign an image to the button.
    button1.Image = Image.FromFile("C:\\Graphics\\MyBitmap.bmp");
    // Align the image and text on the button.
    button1.ImageAlign = ContentAlignment.MiddleRight;    
    button1.TextAlign = ContentAlignment.MiddleLeft;
    // Give the button a flat appearance.
    button1.FlatStyle = FlatStyle.Flat;
 }

Remarks

When the Image property is set, the ImageList property will be set to null, and the ImageIndex property will be set to its default, -1.

Примітка

If the FlatStyle property is set to FlatStyle.System, any images assigned to the Image property are not displayed.

Applies to

Продукт Версії
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also