Compartilhar via


Como definir a tela de fundo de um painel Windows Forms

Um controle do Windows Forms Panel pode exibir uma cor de plano de fundo e uma imagem de plano de fundo. A BackColor propriedade define a cor do plano de fundo para os controles contidos, como rótulos e botões de opção. Se a propriedade não estiver definida, a BackgroundImageBackColor seleção preencherá todo o painel. Se a propriedade estiver definida, a BackgroundImage imagem será exibida atrás dos controles contidos.

Para definir o plano de fundo programaticamente

  1. Defina a propriedade do BackColor painel como um valor do tipo System.Drawing.Color.

    Panel1.BackColor = Color.AliceBlue  
    
    panel1.BackColor = Color.AliceBlue;  
    
    panel1->BackColor = Color::AliceBlue;  
    
  2. Defina a propriedade do BackgroundImage painel usando o FromFileSystem.Drawing.Image método da classe.

    ' 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"));  
    

Confira também