Share via


Comment : définir l'arrière-plan d'un panneau Windows Forms

Mise à jour : novembre 2007

Un contrôle Panel Windows Forms peut afficher une couleur et une image d'arrière-plan. La propriété BackColor définit la couleur d'arrière-plan des contrôles contenus, par exemple les étiquettes et cases d'option. Si la propriété BackgroundImage n'est pas définie, la couleur BackColor sélectionnée remplit tout le contrôle Panel. Si la propriété BackgroundImage est définie, l'image est affichée derrière les contrôles contenus.

Pour définir un arrière-plan par programme

  1. Affectez à la propriété BackColor du contrôle Panel une valeur de type System.Drawing.Color.

    Panel1.BackColor = Color.AliceBlue
    
    panel1.BackColor = Color.AliceBlue;
    
    panel1->BackColor = Color::AliceBlue;
    
  2. Définissez la propriété BackgroundImage du contrôle Panel à l'aide de la méthode FromFile de la 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"));
    

Voir aussi

Référence

Vue d'ensemble du contrôle Panel (Windows Forms)

BackColor

BackgroundImage

Autres ressources

Panel, contrôle (Windows Forms)