ImageList 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 ImageList 类的新实例。
重载
ImageList() |
用 ImageList、ColorDepth 和 ImageSize 的默认值初始化 TransparentColor 类的新实例。 |
ImageList(IContainer) |
初始化 ImageList 类的新实例,将它与一个容器关联起来。 |
ImageList()
- Source:
- ImageList.cs
- Source:
- ImageList.cs
- Source:
- ImageList.cs
用 ImageList、ColorDepth 和 ImageSize 的默认值初始化 TransparentColor 类的新实例。
public:
ImageList();
public ImageList ();
Public Sub New ()
示例
下面的代码示例演示如何构造 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
注解
下表显示了 实例 ImageList的初始属性值。
项 | 说明 |
---|---|
ColorDepth | 在通过 .NET 7 的 .NET Framework 和 .NET (Core) 版本中,默认值为 Depth8Bit。 在 .NET 8 及更高版本中,默认值为 Depth32Bit。 |
ImageSize | 默认值是 Size 高度和宽度为 16 乘 16 的对象。 |
TransparentColor | 默认值是 Transparent。 |
适用于
ImageList(IContainer)
- Source:
- ImageList.cs
- Source:
- ImageList.cs
- Source:
- ImageList.cs
初始化 ImageList 类的新实例,将它与一个容器关联起来。
public:
ImageList(System::ComponentModel::IContainer ^ container);
public ImageList (System.ComponentModel.IContainer container);
new System.Windows.Forms.ImageList : System.ComponentModel.IContainer -> System.Windows.Forms.ImageList
Public Sub New (container As IContainer)
参数
- container
- IContainer
实现 IContainer 的对象,以便与 ImageList 的此实例关联。
注解
构造ImageList函数使你能够将 与任何 Container 对象相关联ImageList。 通过像这样关联 ImageList ,可以将 的生存期 ImageList 控制权移交给 Container。 如果在应用程序中使用多个组件,并且想要同时释放所有这些组件,则这非常有用。 例如,如果将 、 和 与 相关联ToolTip,则对容器调用 Dispose 也会强制释放所有这些Container组件。TimerImageList