Control.BackgroundImage Propriedade

Definição

Recebe ou define a imagem de fundo exibida no controlo.

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

Valor de Propriedade

E Image que representa a imagem a mostrar no fundo do controlo.

Exemplos

O seguinte exemplo de código adiciona a Button a a a a um formulário e define algumas das suas propriedades comuns. O exemplo ancora o botão no canto inferior direito do formulário para que mantenha a sua posição relativa à medida que o formulário é redimensionado. De seguida, define o BackgroundImage e redimensiona o botão para o mesmo tamanho que o Image. O exemplo então define o TabStop para true e define a TabIndex propriedade. Por fim, adiciona um gestor de eventos para gerir o Click evento do botão. Este exemplo exige que tenha um ImageList .imageList1

   // Add a button to a form and set some of its common properties.
private:
   void AddMyButton()
   {
      // Create a button and add it to the form.
      Button^ button1 = gcnew Button;

      // Anchor the button to the bottom right corner of the form
      button1->Anchor = static_cast<AnchorStyles>(AnchorStyles::Bottom | AnchorStyles::Right);

      // Assign a background image.
      button1->BackgroundImage = imageList1->Images[ 0 ];

      // Specify the layout style of the background image. Tile is the default.
      button1->BackgroundImageLayout = ImageLayout::Center;

      // Make the button the same size as the image.
      button1->Size = button1->BackgroundImage->Size;

      // Set the button's TabIndex and TabStop properties.
      button1->TabIndex = 1;
      button1->TabStop = true;

      // Add a delegate to handle the Click event.
      button1->Click += gcnew System::EventHandler( this, &Form1::button1_Click );

      // Add the button to the form.
      this->Controls->Add( button1 );
   }
// Add a button to a form and set some of its common properties.
private void AddMyButton()
{
   // Create a button and add it to the form.
   Button button1 = new Button();

   // Anchor the button to the bottom right corner of the form
   button1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);

   // Assign a background image.
   button1.BackgroundImage = imageList1.Images[0];

   // Specify the layout style of the background image. Tile is the default.
   button1.BackgroundImageLayout = ImageLayout.Center;
   
   // Make the button the same size as the image.
   button1.Size = button1.BackgroundImage.Size;

   // Set the button's TabIndex and TabStop properties.
   button1.TabIndex = 1;
   button1.TabStop = true;

   // Add a delegate to handle the Click event.
   button1.Click += new System.EventHandler(this.button1_Click);

   // Add the button to the form.
   this.Controls.Add(button1);
}
' Add a button to a form and set some of its common properties.
Private Sub AddMyButton()
   ' Create a button and add it to the form.
   Dim button1 As New Button()
   
   ' Anchor the button to the bottom right corner of the form
   button1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
   
   ' Assign a background image.
   button1.BackgroundImage = imageList1.Images(0)

   ' Specify the layout style of the background image. Tile is the default.
   button1.BackgroundImageLayout = ImageLayout.Center
   
   ' Make the button the same size as the image.
   button1.Size = button1.BackgroundImage.Size
   
   ' Set the button's TabIndex and TabStop properties.
   button1.TabIndex = 1
   button1.TabStop = True

   ' Add a delegate to handle the Click event.
   AddHandler button1.Click, AddressOf Me.button1_Click
   
   ' Add the button to the form.
   Me.Controls.Add(button1)
End Sub

Observações

  • Use a BackgroundImage propriedade para colocar uma imagem gráfica num controlo.

Note

Imagens com cores translúcidas ou transparentes não são suportadas pelos controlos do Windows Forms como imagens de fundo.

Esta propriedade não é suportada em controlos filhos cuja RightToLeftLayout propriedade é true.

Notas para Herdeiros

Ao sobrescrever a BackgroundImage propriedade numa classe derivada, use a propriedade da BackgroundImage classe base para estender a implementação base. Caso contrário, deve fornecer toda a implementação. Não é obrigado a anular ambos os get acessórios da BackgroundImage propriedadeset; só pode anular um, se necessário.

Aplica-se a

Ver também