Condividi tramite


Procedura: Impostare lo sfondo di un pannello Windows Form

Un controllo windows Form Panel può visualizzare sia un colore di sfondo che un'immagine di sfondo. La proprietà BackColor imposta il colore di sfondo per i controlli contenuti, ad esempio etichette e pulsanti di opzione. Se la proprietà BackgroundImage non è impostata, la selezione BackColor riempirà l'intero pannello. Se la proprietà BackgroundImage è impostata, l'immagine verrà visualizzata dietro i controlli contenuti.

Per impostare lo sfondo in modo programmatico

  1. Impostare la proprietà BackColor del pannello su un valore di tipo System.Drawing.Color.

    Panel1.BackColor = Color.AliceBlue  
    
    panel1.BackColor = Color.AliceBlue;  
    
    panel1->BackColor = Color::AliceBlue;  
    
  2. Impostare la proprietà BackgroundImage del pannello usando il metodo FromFile della classe System.Drawing.Image.

    ' You should replace the bolded image
    ' in the sample below with an image of your own choosing.  
    Panel1.BackgroundImage = Image.FromFile _  
        (System.Environment.GetFolderPath _  
        (System.Environment.SpecialFolder.Personal) _  
        & "\Image.gif")  
    
    // You should replace the bolded image
    // in the sample below with an image of your own choosing.  
    // Note the escape character used (@) when specifying the path.  
    panel1.BackgroundImage = Image.FromFile  
       (System.Environment.GetFolderPath  
       (System.Environment.SpecialFolder.Personal)  
       + @"\Image.gif");  
    
    // You should replace the bolded image
    // in the sample below with an image of your own choosing.  
    panel1->BackgroundImage = Image::FromFile(String::Concat(  
       System::Environment::GetFolderPath  
       (System::Environment::SpecialFolder::Personal),  
       "\\Image.gif"));  
    

Vedere anche