ImageList.ImageCollection.Add 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将指定的对象添加到 ImageList 中。
重载
Add(Icon) |
将指定图标添加到 ImageList 中。 |
Add(Image) |
将指定图像添加到 ImageList 中。 |
Add(Image, Color) |
将指定图像添加到 ImageList 中,使用指定颜色生成屏蔽。 |
Add(String, Icon) |
将具有指定键的图标添加到集合的末尾处。 |
Add(String, Image) |
将具有指定键的图像添加到集合的末尾处。 |
Add(Icon)
将指定图标添加到 ImageList 中。
public:
void Add(System::Drawing::Icon ^ value);
public void Add (System.Drawing.Icon value);
member this.Add : System.Drawing.Icon -> unit
Public Sub Add (value As Icon)
参数
例外
示例
下面的代码示例演示如何构造、 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
注解
在将它添加到列表中之前,将 Icon 转换为 a Bitmap 。
适用于
Add(Image)
Add(Image, Color)
将指定图像添加到 ImageList 中,使用指定颜色生成屏蔽。
public:
int Add(System::Drawing::Image ^ value, System::Drawing::Color transparentColor);
public int Add (System.Drawing.Image value, System.Drawing.Color transparentColor);
member this.Add : System.Drawing.Image * System.Drawing.Color -> int
Public Function Add (value As Image, transparentColor As Color) As Integer
参数
返回
新添加的图像的索引,如果不能添加图像,则为 -1。
例外
正在添加的图像为 null
。
正在添加的图像不是 Bitmap。
适用于
Add(String, Icon)
将具有指定键的图标添加到集合的末尾处。
public:
void Add(System::String ^ key, System::Drawing::Icon ^ icon);
public void Add (string key, System.Drawing.Icon icon);
member this.Add : string * System.Drawing.Icon -> unit
Public Sub Add (key As String, icon As Icon)
参数
- key
- String
图标的名称。
例外
icon
为 null
。
注解
图像的名称对应于图像中的 ImageList.ImageCollection键。 图像键不区分大小写。
适用于
Add(String, Image)
将具有指定键的图像添加到集合的末尾处。
public:
void Add(System::String ^ key, System::Drawing::Image ^ image);
public void Add (string key, System.Drawing.Image image);
member this.Add : string * System.Drawing.Image -> unit
Public Sub Add (key As String, image As Image)
参数
- key
- String
图像的名称。
例外
image
为 null
。
注解
图像的名称对应于图像中的 ImageList.ImageCollection键。 图像键不区分大小写。