在.NET开发中,创建图像列表(ImageList)是一个常见的需求,尤其是在开发图形用户界面时。然而,手动创建和管理这些图像列表可能会非常繁琐。幸运的是,有一款名为ImageList Maker的工具,可以帮助开发者简化这个过程。
ImageList Maker是一个.NET驱动的向导程序,它可以帮助开发者创建图像列表集合。使用这个向导创建图像列表非常简单直接。该应用程序会创建一个C#源文件,并且如果指定的话,它还会创建并编译一个程序集。
要使用ImageList Maker,需要满足以下系统要求:
以下是使用ImageList Maker生成的源代码的截图。如果选择向导中的选项,这段代码将自动编译为一个程序集DLL。
namespace MyNamespace
{
using System;
using System.Resources;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
using System.ComponentModel;
public class MyImageList
{
private ArrayList imgNames;
private ImageList _imageList;
// Get Set property for imagelist
public ImageList TheImageList
{
get { return _imageList; }
set { _imageList = value; }
}
// Get property for image names
public ArrayList ImageNames
{
get { return imgNames; }
}
// Constructor
public MyImageList()
{
_init();
}
// Retrives image index in this image list by saved filename
public int GetIndex(string iname)
{
return imgNames.IndexOf(iname);
}
// Initializing image list
private void _init()
{
// Creating a resource manager containing the images
ResourceManager Rm = new ResourceManager("TSIML_MyImageList", GetType().Assembly);
// General
_imageList = new ImageList();
_imageList.ImageSize = new Size((int)Rm.GetObject("IWIDTH"), (int)Rm.GetObject("IHEIGHT"));
_imageList.TransparentColor = (Color)Rm.GetObject("ITRANS");
_imageList.ColorDepth = ColorDepth.Depth32Bit;
// Getting image names
imgNames = (ArrayList)Rm.GetObject("INAMES");
// Loadng images in the image list
foreach (object name in imgNames)
{
_imageList.Images.Add((Image)Rm.GetObject((string)name));
}
}
}
}
namespace TrueSoftware
{
using System;
using System.Windows.Forms;
using System.Resources;
using MyNamespace;
public class MyImageList_TestApp : Form
{
public MyImageList_TestApp()
{
// General
Width = 320;
Height = 200;
Text = "MyImageList Test Application by TrueSoftware";
StartPosition = FormStartPosition.CenterScreen;
// Creating and Populating a listview
MyImageList imgMyImageList = new MyImageList();
ListView lvTestView = new ListView();
// ********************************************
// Assigning the imgMyImageList.TheImageList to the listview's LargeImageList
lvTestView.LargeImageList = imgMyImageList.TheImageList;
// Populating
foreach (object name in imgMyImageList.ImageNames)
{
lvTestView.Items.Add((string)name, imgMyImageList.GetIndex((string)name));
}
// Setting some properties
lvTestView.Dock = DockStyle.Fill;
// Adding listview to the main form
Controls.Add(lvTestView);
}
public static void Main(string[] args)
{
Application.Run(new MyImageList_TestApp());
}
}
}