using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace HelloWinForm { public partial class ImageListFrm : Form { string exePath; public ImageListFrm() { InitializeComponent(); } private void ImageListFrm_Load(object sender, EventArgs e) { //取得exe文件所在目录的方法 exePath = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("//")); //初始化ImageList InitImageList(); //在PictrueBox上画 picShow.Image = ilsTest.Images[0]; //picShow.Image = ilsTest.Images[1]; //ToolStrip的ImageList属性 this.tlsToolStrip.ImageList = this.ilsTest; this.tlsToolStrip.Items[0].Image = ilsTest.Images[0]; this.tlsToolStrip.Items[1].ImageIndex = 1; } private void InitImageList() { //图片资源,如果要输出,在属性里修改为:始终复制 ilsTest.Images.Add(Image.FromFile(exePath + "//resource//blackstone.gif", true)); ilsTest.Images.Add(Image.FromFile(exePath + "//resource//whitestone.gif", true)); } private void btnDraw_Click(object sender, EventArgs e) { //在指定的Graphics上画Image ilsTest.Draw(this.CreateGraphics(), new Point(100, 100), 1); } } }