Control.BackgroundImage Egenskap

Definition

Hämtar eller anger bakgrundsbilden som visas i kontrollen.

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

Egenskapsvärde

En Image som representerar bilden som ska visas i bakgrunden av kontrollen.

Exempel

I följande kodexempel läggs ett Button till i ett formulär och några av dess gemensamma egenskaper anges. Exemplet fäster knappen i formulärets nedre högra hörn så att den behåller sin relativa position när formuläret ändras. Därefter ställer den BackgroundImage in och ändrar storlek på knappen till samma storlek som Image. Exemplet anger TabStop sedan egenskapen till true och TabIndex . Slutligen lägger den till en händelsehanterare för att hantera Click händelsen för knappen. Det här exemplet kräver att du har namnet ImageListimageList1.

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

Kommentarer

  • Använd egenskapen BackgroundImage för att placera en bild på en kontroll.

Note

Bilder med genomskinliga eller transparenta färger stöds inte av Windows Forms kontroller som bakgrundsbilder.

Den här egenskapen stöds inte för underordnade kontroller vars RightToLeftLayout egenskap är true.

Anteckningar till arvingar

När du åsidosättar BackgroundImage egenskapen i en härledd klass använder du basklassens BackgroundImage egenskap för att utöka basimplementeringen. Annars måste du ange all implementering. Du behöver inte åsidosätta både get egenskapens och set -åtkomsten BackgroundImage . Du kan bara åsidosätta en om det behövs.

Gäller för

Se även