`在C#中如何使用imagelist

`在C#中如何使用imagelist,第1张

拖出来一个ImageList,在他的属性列表中找到Images,点击""按钮,

在d出来的对话框中点击"添加"加入你要的,并记好每个前边的编号点确定

listview1ItemsAdd(new ListViewItem(new String[]{"张三,广东,男"},<类型int,他的头像在ImageList中的编号>)

方法如下

(1)新建一个VB工程

(2)在控件工具箱中添加ListView和ImageList控件

在工具箱上鼠标右键单击-->调出菜单

(3)在窗体上布置一个ListView和一个ImageList

(4)向ImageList1中插入

鼠标右键单击ImageList1-->调出菜单-->属性

(5)将ListView1与ImageList关联起来

鼠标右键单击ListView1-->调出菜单-->属性

(6)窗体代码

Option Explicit

Private Sub Form_Load()

    '向ListView1中添加项

    Dim itemX As ListItem

    With ListView1

        Set itemX = ListItemsAdd(, , "项目1")

        '使用ImageList1中的#1图

        itemXIcon = 1

        

        Set itemX = ListItemsAdd(, , "项目2")

        '使用ImageList1中的#2图

        itemXIcon = 2

    End With

End Sub

(7)运行效果

不会将faviconico换成faviconjpg或faviconbmp啊…………

将其它PICBOX控件里的路径取出存入imageList即可。

msdn中的实例:

C# 复制代码

internal SystemWindowsFormsImageList ImageList1;

// Create an ImageList Object, populate it, and display

// the images it contains

private void Button1_Click(SystemObject sender,

SystemEventArgs e)

{

// Construct the ImageList

ImageList1 = new ImageList();

// Set the ImageSize property to a larger size

// (the default is 16 x 16)

ImageList1ImageSize = new Size(112, 112);

// Add two images to the list

ImageList1ImagesAdd(

ImageFromFile("c:\\windows\\FeatherTexturebmp"));

ImageList1ImagesAdd(

ImageFromFile("C:\\windows\\Gone Fishingbmp"));

// Get a Graphics object from the form's handle

Graphics theGraphics = GraphicsFromHwnd(thisHandle);

// Loop through the images in the list, drawing each image

for(int count = 0; count < ImageList1ImagesCount; count++)

{

ImageList1Draw(theGraphics, new Point(85, 85), count);

// Call ApplicationDoEvents to force a repaint of the form

ApplicationDoEvents();

// Call the Sleep method to allow the user to see the image

SystemThreadingThreadSleep(1000);

}

}

明白吗?难道你会认为imageListImagesAdd()是把地址中的存放在imageList中???

增加:

ImageList imageList = new ImageList();

imageListImagesAdd(ImageFromFile(@"D:\我的文件\myrice\faviconico"));

imageListImagesAdd(ImageFromFile(@"D:\我的文件\myrice\favicon4ico"));

imageListImagesAdd(ImageFromFile(@"D:\我的文件\myrice\favicon5ico"));

读取一

thislb = new GListBox();

lbImageList = imageList;

读取二

imageListImages[a],括号内为索引,表示你要取的序号,不得超过imageListImagescount的数量,不然会报错。

为什么不去看msdn??

建议不要用picturebox控件

改成listview控件更好,使用LargeIcon样式

至于获取文件

可以用

DirectoryInfo d = new DirectoryInfo("C:\\pic\\");

FileInfo[] fs = dGetFiles("jpg");

///////////////////////////////////////

在form上拖一个ListView控件,设置Dock为Fill,View为LargeIcon,然后代码如下

using System;

using SystemCollectionsGeneric;

using SystemComponentModel;

using SystemData;

using SystemDrawing;

using SystemText;

using SystemWindowsForms;

using SystemIO;

namespace WindowsApplication1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Shown(object sender, EventArgs e)

{

DirectoryInfo d = new DirectoryInfo(@"E:\My Documents\My Pictures\bmw\");//目录

FileInfo[] fs = dGetFiles("jpg");//格式

ImageList il = new ImageList();

ilColorDepth = ColorDepthDepth32Bit;

ilImageSize = new Size(100, 100);//显示大小

thislistView1LargeImageList = il;

for(int i=0;i<fsLength;i++)

{

ilImagesAdd(ImageFromFile(fs[i]FullName));

thislistView1ItemsAdd(fs[i]Name, i);

}

}

}

}

以上就是关于`在C#中如何使用imagelist全部的内容,包括:`在C#中如何使用imagelist、VB中如何在ListView中添加ImageList中的图像、C#中imageList动态添加图片问题等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9670642.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-30
下一篇2023-04-30

发表评论

登录后才能评论

评论列表(0条)

    保存