ImageList.ImageSize プロパティ

定義

イメージ リスト内のイメージのサイズを取得または設定します。

C#
public System.Drawing.Size ImageSize { get; set; }

プロパティ値

Size

リスト内のイメージの高さと幅をピクセル単位で定義する Size。 既定のサイズは 16 × 16 です。 最大サイズは 256 × 256 です。

例外

代入された値が IsEmpty と同じです。

  • または - 高さまたは幅の値が 0 以下です。

  • または - 高さまたは幅の値が 256 を超えています。

新しいサイズが 0 未満か、256 を超えています。

次のコード例では、イメージをプロパティに追加し ImageList、プロパティを Images 設定し、メソッドを ImageSize 使用して、作成する方法を Draw 示します。 この例を実行するには、ボタンを Button1含むフォームに配置します。 この例では、c:\Windows\ のFeatherTexture.bmp存在をGone Fishing.bmp前提としています。 ビットマップがシステム上に存在しない場合、または別の場所に存在する場合は、それに応じて例を変更します。

C#
internal System.Windows.Forms.ImageList ImageList1;

// Create an ImageList Object, populate it, and display
// the images it contains.
private void Button1_Click(System.Object sender, 
    System.EventArgs e)
{

    // Construct the ImageList.
    ImageList1 = new ImageList();

    // Set the ImageSize property to a larger size 
    // (the default is 16 x 16).
    ImageList1.ImageSize = new Size(112, 112);

    // Add two images to the list.
    ImageList1.Images.Add(
        Image.FromFile("c:\\windows\\FeatherTexture.bmp"));
    ImageList1.Images.Add(
        Image.FromFile("C:\\windows\\Gone Fishing.bmp"));

    // Get a Graphics object from the form's handle.
    Graphics theGraphics = Graphics.FromHwnd(this.Handle);

    // Loop through the images in the list, drawing each image.
    for(int count = 0; count < ImageList1.Images.Count; count++)
    {
        ImageList1.Draw(theGraphics, new Point(85, 85), count);

        // Call Application.DoEvents to force a repaint of the form.
        Application.DoEvents();

        // Call the Sleep method to allow the user to see the image.
        System.Threading.Thread.Sleep(1000);
    }
}

注釈

イメージ コレクション ImageSize にイメージを追加する前にプロパティを設定すると、指定したイメージ サイズにイメージのサイズが変更されます。

プロパティを ImageSize 新しい値に設定すると、 Handle イメージ リストの値が再作成されます。

プロパティを ImageSize 設定するとハンドルが再作成されるため、プロパティを設定する前に設定 ImageSize する Images 必要があります。 ハンドルがImageList作成されると、プロパティを設定した後、コードでプロパティをImageSize設定ColorDepthImagesすると、プロパティに設定されたイメージのコレクションがImages削除されます。

適用対象

製品 バージョン
.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
Windows Desktop 3.0, 3.1, 5, 6, 7