次の方法で共有


Control.BackgroundImage プロパティ

定義

コントロールに表示される背景イメージを取得または設定します。

public:
 virtual property System::Drawing::Image ^ BackgroundImage { System::Drawing::Image ^ get(); void set(System::Drawing::Image ^ value); };
public virtual System.Drawing.Image BackgroundImage { get; set; }
public virtual System.Drawing.Image? BackgroundImage { get; set; }
member this.BackgroundImage : System.Drawing.Image with get, set
Public Overridable Property BackgroundImage As Image

プロパティ値

コントロールの背景に表示するイメージを表す Image

次のコード例では、フォームに Button を追加し、その共通プロパティの一部を設定します。 次の使用例は、フォームの右下隅にボタンを固定し、フォームのサイズ変更時に相対的な位置を維持します。 次に、 BackgroundImage を設定し、ボタンのサイズを Imageと同じサイズに変更します。 次に、 TabStoptrue に設定し、 TabIndex プロパティを設定します。 最後に、ボタンの Click イベントを処理するイベント ハンドラーを追加します。 この例では、imageList1という名前のImageListが必要です。

   // Add a button to a form and set some of its common properties.
private:
   void AddMyButton()
   {
      // Create a button and add it to the form.
      Button^ button1 = gcnew Button;

      // Anchor the button to the bottom right corner of the form
      button1->Anchor = static_cast<AnchorStyles>(AnchorStyles::Bottom | AnchorStyles::Right);

      // Assign a background image.
      button1->BackgroundImage = imageList1->Images[ 0 ];

      // Specify the layout style of the background image. Tile is the default.
      button1->BackgroundImageLayout = ImageLayout::Center;

      // Make the button the same size as the image.
      button1->Size = button1->BackgroundImage->Size;

      // Set the button's TabIndex and TabStop properties.
      button1->TabIndex = 1;
      button1->TabStop = true;

      // Add a delegate to handle the Click event.
      button1->Click += gcnew System::EventHandler( this, &Form1::button1_Click );

      // Add the button to the form.
      this->Controls->Add( button1 );
   }
// Add a button to a form and set some of its common properties.
private void AddMyButton()
{
   // Create a button and add it to the form.
   Button button1 = new Button();

   // Anchor the button to the bottom right corner of the form
   button1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);

   // Assign a background image.
   button1.BackgroundImage = imageList1.Images[0];

   // Specify the layout style of the background image. Tile is the default.
   button1.BackgroundImageLayout = ImageLayout.Center;
   
   // Make the button the same size as the image.
   button1.Size = button1.BackgroundImage.Size;

   // Set the button's TabIndex and TabStop properties.
   button1.TabIndex = 1;
   button1.TabStop = true;

   // Add a delegate to handle the Click event.
   button1.Click += new System.EventHandler(this.button1_Click);

   // Add the button to the form.
   this.Controls.Add(button1);
}
' Add a button to a form and set some of its common properties.
Private Sub AddMyButton()
   ' Create a button and add it to the form.
   Dim button1 As New Button()
   
   ' Anchor the button to the bottom right corner of the form
   button1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
   
   ' Assign a background image.
   button1.BackgroundImage = imageList1.Images(0)

   ' Specify the layout style of the background image. Tile is the default.
   button1.BackgroundImageLayout = ImageLayout.Center
   
   ' Make the button the same size as the image.
   button1.Size = button1.BackgroundImage.Size
   
   ' Set the button's TabIndex and TabStop properties.
   button1.TabIndex = 1
   button1.TabStop = True

   ' Add a delegate to handle the Click event.
   AddHandler button1.Click, AddressOf Me.button1_Click
   
   ' Add the button to the form.
   Me.Controls.Add(button1)
End Sub

注釈

  • BackgroundImage プロパティを使用して、グラフィックイメージをコントロールに配置します。

半透明または透明な色の画像は、Windows フォーム コントロールでは背景画像としてサポートされていません。

このプロパティは、 RightToLeftLayout プロパティが true子コントロールではサポートされていません。

注意 (継承者)

派生クラスの BackgroundImage プロパティをオーバーライドする場合は、基底クラスの BackgroundImage プロパティを使用して基本実装を拡張します。 それ以外の場合は、すべての実装を指定する必要があります。 BackgroundImage プロパティのgetアクセサーと set アクセサーの両方をオーバーライドする必要はありません。必要に応じて 1 つだけオーバーライドできます。

適用対象

こちらもご覧ください