ButtonBase.Image Propriedade

Definição

Obtém ou define a imagem que é exibida num controlo de botão.

public:
 property System::Drawing::Image ^ Image { System::Drawing::Image ^ get(); void set(System::Drawing::Image ^ value); };
public System.Drawing.Image Image { get; set; }
member this.Image : System.Drawing.Image with get, set
Public Property Image As Image

Valor de Propriedade

É Image mostrado no controlo do botão. O valor predefinido é null.

Exemplos

O seguinte exemplo de código usa a classe derivada Button e define algumas das suas propriedades comuns. O resultado será um botão plano com texto à esquerda e uma imagem à direita. Este código exige que tenha uma imagem bitmap nomeada MyBitMap.bmp armazenada no C:\Graphics diretório e que uma referência ao System.Drawing namespace seja incluída.

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;
   }
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;
 }
Private Sub 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
End Sub

Observações

Quando a Image propriedade é definida, a ImageList propriedade será definida para null, e a ImageIndex propriedade será definida para o seu padrão, -1.

Note

Se a FlatStyle propriedade estiver definida para FlatStyle.System, quaisquer imagens atribuídas à Image propriedade não são exibidas.

Aplica-se a

Ver também