Udostępnij za pośrednictwem


Instrukcje: ustawianie tła panelu formularzy systemu Windows

Kontrolka windows Forms Panel może wyświetlać zarówno kolor tła, jak i obraz tła. Właściwość BackColor ustawia kolor tła dla zawartych kontrolek, takich jak etykiety i przyciski radiowe. Jeśli właściwość BackgroundImage nie jest ustawiona, zaznaczenie BackColor wypełni cały panel. Jeśli właściwość BackgroundImage jest ustawiona, obraz zostanie wyświetlony za zawartymi kontrolkami.

Aby programowo ustawić tło

  1. Ustaw właściwość BackColor panelu na wartość typu System.Drawing.Color.

    Panel1.BackColor = Color.AliceBlue  
    
    panel1.BackColor = Color.AliceBlue;  
    
    panel1->BackColor = Color::AliceBlue;  
    
  2. Ustaw właściwość BackgroundImage panelu przy użyciu metody FromFile klasy 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"));  
    

Zobacz też