Control.BackgroundImage プロパティ

定義

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

C#
public virtual System.Drawing.Image BackgroundImage { get; set; }
C#
public virtual System.Drawing.Image? BackgroundImage { get; set; }

プロパティ値

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

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

C#
// 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);
}

注釈

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

注意

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

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

注意 (継承者)

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

適用対象

製品 バージョン
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

こちらもご覧ください