Freigeben über


Control.BackgroundImage Eigenschaft

Definition

Ruft das Hintergrundbild ab, das im Steuerelement angezeigt wird, oder legt es fest.

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

Eigenschaftswert

Ein Image Wert, der das Bild darstellt, das im Hintergrund des Steuerelements angezeigt werden soll.

Beispiele

Im folgenden Codebeispiel wird einem Formular ein Button Formular hinzugefügt und einige seiner allgemeinen Eigenschaften festgelegt. Im Beispiel wird die Schaltfläche an der unteren rechten Ecke des Formulars verankert, sodass die relative Position beibehalten wird, während die Größe des Formulars geändert wird. Als Nächstes legt sie die BackgroundImage Schaltfläche auf dieselbe Größe fest und ändert sie auf die gleiche Größe wie die Image. Anschließend legt das Beispiel die TabStop Eigenschaft auf true und legt sie TabIndex fest. Schließlich wird ein Ereignishandler zum Behandeln des Click Ereignisses der Schaltfläche hinzugefügt. Dieses Beispiel erfordert, dass Sie einen ImageList Namen imageList1haben.

   // 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

Hinweise

  • Verwenden Sie die BackgroundImage Eigenschaft, um ein Grafikbild auf ein Steuerelement zu platzieren.

Hinweis

Bilder mit transluzenten oder transparenten Farben werden von Windows Forms-Steuerelementen nicht als Hintergrundbilder unterstützt.

Diese Eigenschaft wird für untergeordnete Steuerelemente, deren RightToLeftLayout Eigenschaft lautet true, nicht unterstützt.

Hinweise für Vererber

Verwenden Sie beim Überschreiben der BackgroundImage Eigenschaft in einer abgeleiteten Klasse die Eigenschaft der Basisklasse BackgroundImage , um die Basisimplementierung zu erweitern. Andernfalls müssen Sie alle Implementierungen bereitstellen. Sie müssen die get Eigenschaften und set Accessoren BackgroundImage nicht außer Kraft setzen. Sie können bei Bedarf nur eine außer Kraft setzen.

Gilt für:

Weitere Informationen