ImageList.ImageSize 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置图像列表中的图像大小。
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。 默认大小是 16 x 16。 最大大小是 256 x 256。
例外
新大小有一个维度小于 0 或大于 256。
示例
下面的代码示例演示如何构造一个 ImageList、向属性添加图像 Images 、设置 ImageSize 属性和使用 Draw 该方法。 若要运行此示例,请将其置于包含名为 Button1
按钮的窗体中。 此示例假定存在 FeatherTexture.bmp
Gone Fishing.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会导致重新创建句柄,因此应在设置属性之前进行设置ImageSizeImages。 创建句柄ImageList后,在设置Images属性后,在代码中设置ColorDepth或ImageSize属性将导致为该属性设置Images的图像集合被删除。