Freigeben über


Control.BackgroundImage-Eigenschaft

Ruft das im Steuerelement angezeigte Hintergrundbild ab oder legt dieses fest.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
<LocalizableAttribute(True)> _
Public Overridable Property BackgroundImage As Image
'Usage
Dim instance As Control
Dim value As Image

value = instance.BackgroundImage

instance.BackgroundImage = value
[LocalizableAttribute(true)] 
public virtual Image BackgroundImage { get; set; }
[LocalizableAttribute(true)] 
public:
virtual property Image^ BackgroundImage {
    Image^ get ();
    void set (Image^ value);
}
/** @property */
public Image get_BackgroundImage ()

/** @property */
public void set_BackgroundImage (Image value)
public function get BackgroundImage () : Image

public function set BackgroundImage (value : Image)

Eigenschaftenwert

Ein Image, das das im Hintergrund des Steuerelements anzuzeigende Bild darstellt.

Hinweise

  • Platzieren Sie mithilfe der BackgroundImage-Eigenschaft ein grafisches Bild auf einem Steuerelement.

Hinweis

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

Diese Eigenschaft wird nicht für untergeordnete Steuerelementen unterstützt, deren RightToLeftLayout-Eigenschaft true ist.

Hinweise für Erben Verwenden Sie beim Überschreiben der BackgroundImage-Eigenschaft in einer abgeleiteten Klasse die BackgroundImage-Eigenschaft der Basisklasse, um die Basisimplementierung zu erweitern. Andernfalls müssen Sie die gesamte Implementierung bereitstellen. Sie müssen nicht sowohl den get-Accessor als auch den set-Accessor der BackgroundImage-Eigenschaft überschreiben. Sie können ggf. auch nur einen Accessor überschreiben.

Beispiel

Im folgenden Codebeispiel wird einem Formular ein Button hinzugefügt, und es werden einige allgemeine Eigenschaften festgelegt. Im Beispiel wird die Schaltfläche in der rechten unteren Ecke des Formulars verankert, sodass sie auch dann ihre relative Position beibehält, wenn die Größe des Formulars geändert wird. Nach dem Festlegen des BackgroundImage wird die Größe der Schaltfläche auf die gleiche Größe wie das Image angepasst. Im Beispiel wird dann der TabStop auf true festgelegt. Außerdem wird die TabIndex-Eigenschaft festgelegt. Abschließend wird ein Ereignishandler hinzugefügt, um das Click-Ereignis der Schaltfläche zu behandeln. In diesem Beispiel muss ein ImageList mit der Bezeichnung imageList1 vorhanden sein.

' 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
// 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:
   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.set_Anchor(AnchorStyles.Bottom | AnchorStyles.Right);
    // Assign a background image.
    button1.set_BackgroundImage(imageList1.get_Images().get_Item(0));
    // Specify the layout style of the background image. Tile is the 
    // default.
    button1.set_BackgroundImageLayout(ImageLayout.Center);
    // Make the button the same size as the image.
    button1.set_Size(button1.get_BackgroundImage().get_Size());
    // Set the button's TabIndex and TabStop properties.
    button1.set_TabIndex(1);
    button1.set_TabStop(true);
    // Add a delegate to handle the Click event.
    button1.add_Click(new System.EventHandler(this.button1_Click));
    // Add the button to the form.
    this.get_Controls().Add(button1);
} //AddMyButton

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

Control-Klasse
Control-Member
System.Windows.Forms-Namespace
Image
BackgroundImageChanged
BackgroundImageLayout
BackgroundImageLayoutChanged
OnBackgroundImageChanged
OnBackgroundImageLayoutChanged