Control.BackgroundImage Propriété

Définition

Obtient ou définit l'image d'arrière-plan affichée dans le contrôle.

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; }
public virtual System.Drawing.Image? BackgroundImage { get; set; }
member this.BackgroundImage : System.Drawing.Image with get, set
Public Overridable Property BackgroundImage As Image

Valeur de propriété

Image qui représente l'image à afficher à l'arrière-plan du contrôle.

Exemples

L’exemple de code suivant ajoute un Button à un formulaire et définit certaines de ses propriétés communes. L’exemple ancre le bouton dans le coin inférieur droit du formulaire afin qu’il conserve sa position relative à mesure que le formulaire est redimensionné. Ensuite, il définit le BackgroundImage et redimensionne le bouton à la même taille que le Image. L’exemple définit ensuite la TabStoptrue valeur et définit la TabIndex propriété . Enfin, il ajoute un gestionnaire d’événements pour gérer l’événement Click du bouton. Cet exemple nécessite que vous ayez un ImageList nommé 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

Remarques

  • Utilisez la BackgroundImage propriété pour placer une image graphique sur un contrôle.

Notes

Les images avec des couleurs translucides ou transparentes ne sont pas prises en charge par les contrôles Windows Forms en tant qu’images d’arrière-plan.

Cette propriété n’est pas prise en charge sur les contrôles enfants dont RightToLeftLayout la propriété est true.

Notes pour les héritiers

Lorsque vous substituez la BackgroundImage propriété dans une classe dérivée, utilisez la propriété de la classe de BackgroundImage base pour étendre l’implémentation de base. Sinon, vous devez fournir toute l’implémentation. Vous n’êtes pas obligé de remplacer les get accesseurs et set de la BackgroundImage propriété ; vous ne pouvez remplacer qu’un seul si nécessaire.

S’applique à

Voir aussi