Proprietà Control.BackgroundImage (System.Windows.Forms)

Cambia visualizzazione:
ScriptFree
Riferimento a .NET Framework
Proprietà Control.BackgroundImage

Ottiene o imposta l'immagine di sfondo visualizzata nel controllo.

Spazio dei nomi: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Sintassi

Visual Basic - (Dichiarazione)
<LocalizableAttribute(True)> _
Public Overridable Property BackgroundImage As Image
Visual Basic (Utilizzo)
Dim instance As Control
Dim value As Image

value = instance.BackgroundImage

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

/** @property */
public void set_BackgroundImage (Image value)

JScript
public function get BackgroundImage () : Image

public function set BackgroundImage (value : Image)

Valore proprietà

Oggetto Image che rappresenta l'immagine da visualizzare sullo sfondo del controllo.
Note

  • Utilizzare la proprietà BackgroundImage per inserire un'immagine grafica in un controllo.

NotaNota

Le immagini con colori semitrasparenti o trasparenti non sono supportate come immagini di sfondo dai controlli Windows Form.

Questa proprietà non è supportata nei controlli figlio la cui proprietà RightToLeftLayout è true.

Note sull'ereditarietà: Quando si esegue l'override della proprietà BackgroundImage in una classe derivata, utilizzare la proprietà BackgroundImage della classe base per estendere l'implementazione base. In caso contrario, sarà necessario fornire l'intera implementazione. Non è necessario eseguire l'override di entrambe le funzioni di accesso get e set della proprietà BackgroundImage. È sufficiente eseguire l'override di una soltanto di esse, se necessario.

Esempio

Nell'esempio di codice riportato di seguito viene aggiunto un oggetto Button a un form e vengono impostate alcune proprietà comuni dell'oggetto. Nell'esempio il pulsante è ancorato all'angolo inferiore destro del form e pertanto mantiene la posizione relativa quando il form viene ridimensionato. Viene quindi impostata la proprietà BackgroundImage e il pulsante viene portato alle stesse dimensioni dell'oggetto Image. Nell'esempio la proprietà TabStop viene impostata su true e viene impostata la proprietà TabIndex. Infine, viene aggiunto un gestore eventi per gestire l'evento Click del pulsante. Per eseguire questo esempio è necessario che sia disponibile un oggetto ImageList denominato imageList1.

Visual Basic
' 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

C#
// 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);
}

C++
   // 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 );
   }

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

Piattaforme

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

.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema.

Informazioni sulla versione

.NET Framework

Supportato in: 2.0 1.1 1.0
Vedere anche