ImageList.Images 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取此图像列表的 ImageList.ImageCollection。
public:
property System::Windows::Forms::ImageList::ImageCollection ^ Images { System::Windows::Forms::ImageList::ImageCollection ^ get(); };
public System.Windows.Forms.ImageList.ImageCollection Images { get; }
member this.Images : System.Windows.Forms.ImageList.ImageCollection
Public ReadOnly Property Images As ImageList.ImageCollection
属性值
图像集合。
示例
下面的代码示例演示如何构造 ImageList、将图像添加到 Images 属性、设置 ImageSize 属性以及使用 Draw 方法。 若要运行此示例,请将其置于包含名为 的按钮的 Button1
窗体中。 该示例假定 c:\Windows\ 处存在 FeatherTexture.bmp
和 Gone Fishing.bmp
。 如果系统中不存在位图,或者位于其他位置,请相应地更改示例。
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
注解
如果尚未创建映像集合,则会在检索此属性时创建该集合。