Control.BackgroundImage Eigenschap
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee haalt u de achtergrondafbeelding op die in het besturingselement wordt weergegeven of stelt u deze in.
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
Waarde van eigenschap
Een Image afbeelding die de afbeelding weergeeft die op de achtergrond van het besturingselement moet worden weergegeven.
Voorbeelden
In het volgende codevoorbeeld wordt een Button formulier toegevoegd en worden enkele algemene eigenschappen ervan ingesteld. In het voorbeeld wordt de knop in de rechterbenedenhoek van het formulier verankerd, zodat de relatieve positie behouden blijft wanneer het formulier wordt gewijzigd. Vervolgens stelt u de knop in BackgroundImage en wijzigt u de grootte van de knop op dezelfde grootte als de Image. In het voorbeeld wordt vervolgens de TabStoptrue eigenschap ingesteld TabIndex op en ingesteld. Ten slotte wordt er een gebeurtenis-handler toegevoegd om de Click gebeurtenis van de knop af te handelen. In dit voorbeeld moet u een ImageList naam imageList1hebben.
// 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
Opmerkingen
- Gebruik de BackgroundImage eigenschap om een afbeelding op een besturingselement te plaatsen.
Note
Afbeeldingen met doorzichtige of transparante kleuren worden niet ondersteund door Windows Forms besturingselementen als achtergrondafbeeldingen.
Deze eigenschap wordt niet ondersteund voor onderliggende besturingselementen waarvan RightToLeftLayout de eigenschap is true.
Notities voor overnemers
Wanneer u de BackgroundImage eigenschap in een afgeleide klasse overschrijft, gebruikt u de eigenschap van BackgroundImage de basisklasse om de basis-implementatie uit te breiden. Anders moet u alle implementaties opgeven. U hoeft niet zowel de getset eigenschap als de BackgroundImage toegangsrechten te overschrijven. U kunt er slechts één overschrijven als dat nodig is.