Compartilhar via


Como definir a tela de fundo de um painel do Windows Forms

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

Para definir o plano de fundo programaticamente

  1. Defina a propriedade BackColor do 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 FromFile método da System.Drawing.Image 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"));
    

Consulte também