次の方法で共有


方法: Windows フォーム パネルの背景を設定する

Windows フォーム Panel コントロールでは、背景色と背景画像の両方を表示できます。 BackColor プロパティは、ラベルやラジオ ボタンなど、含まれているコントロールの背景色を設定します。 BackgroundImage プロパティが設定されていない場合は、BackColor 選択がパネル全体に表示されます。 BackgroundImage プロパティが設定されている場合、イメージは含まれているコントロールの背後に表示されます。

プログラムで背景を設定するには

  1. パネルの BackColor プロパティを System.Drawing.Color型の値に設定します。

    Panel1.BackColor = Color.AliceBlue
    
    panel1.BackColor = Color.AliceBlue;
    
    panel1->BackColor = Color::AliceBlue;
    
  2. BackgroundImage クラスの FromFile メソッドを使用して、パネルの 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"));
    

こちらも参照ください