共用方式為


ImageList.ImageSize 屬性

定義

取得或設定影像清單中的影像大小。

public:
 property System::Drawing::Size ImageSize { System::Drawing::Size get(); void set(System::Drawing::Size value); };
public System.Drawing.Size ImageSize { get; set; }
member this.ImageSize : System.Drawing.Size with get, set
Public Property ImageSize As Size

屬性值

Size

Size,定義清單中的影像高度和寬度 (以像素為單位)。 預設大小是 16 x 16。 最大大小是 256 x 256。

例外狀況

指派的值等於 IsEmpty

-或- 高度或寬度的值小於或等於 0。

-或- 高度或寬度的值大於 256。

新的大小具有小於 0 或大於 256 的維度 (Dimension)。

範例

下列程式碼範例示範建構 ImageList 、將影像新增至 Images 屬性、設定 ImageSize 屬性,以及使用 Draw 方法。 若要執行此範例,請將它放在包含名為 Button1 按鈕的表單中。 此範例假設 和 Gone Fishing.bmp 存在於 FeatherTexture.bmp c:\Windows \ 。 如果點陣圖不存在於您的系統上,或存在於另一個位置,請據以變更範例。

internal:
   System::Windows::Forms::ImageList^ ImageList1;

private:

   // Create an ImageList Object, populate it, and display
   // the images it contains.
   void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      
      // Construct the ImageList.
      ImageList1 = gcnew ImageList;
      
      // Set the ImageSize property to a larger size 
      // (the default is 16 x 16).
      ImageList1->ImageSize = System::Drawing::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, 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 );

      }
   }
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);
    }
}
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList

' Create an ImageList Object, populate it, and display
' the images it contains.
Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    ' 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"))

    Dim count As System.Int32

    ' Get a Graphics object from the form's handle.
    Dim theGraphics As Graphics = Graphics.FromHwnd(Me.Handle)

    ' Loop through the images in the list, drawing each image.
    For count = 0 To ImageList1.Images.Count - 1
        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)
    Next
End Sub

備註

ImageSize將影像新增至影像集合之前設定 屬性,會導致影像調整大小為指定的影像大小。

當您將 ImageSize 屬性設定為新值時, Handle 會重新建立映射清單的 。

因為設定 ImageSize 屬性會導致重新建立控制碼,所以您應該在設定 Images 屬性之前設定 ImageSize 。 建立 的控制碼 ImageList 之後,在設定 Images 屬性之後,在程式碼中設定 ColorDepthImageSize 屬性時,會導致設定屬性的影像 Images 集合遭到刪除。

適用於