/**************************************************/
/*★ ListView にアイコンを付けて表示 前田 稔 ★*/
/**************************************************/
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyForm : Form
{
ListView listView1;
ImageList imageListSmall;
string[] Files =
{ "C:\\DATA\\Test\\Icon01.ico", "C:\\DATA\\Test\\Icon02.ico", "C:\\DATA\\Test\\Icon03.ico" };
public MyForm()
{
InitializeComponent();
Load += new System.EventHandler(MyForm_Load);
}
private void InitializeComponent()
{
this.listView1 = new System.Windows.Forms.ListView();
this.SuspendLayout();
//
// listView1
//
this.listView1.Location = new System.Drawing.Point(12, 12);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(258, 232);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.List;
//this.listView1.Sorted = true;
//
// MyForm
//
this.ClientSize = new System.Drawing.Size(282, 256);
this.Controls.Add(this.listView1);
this.Name = "MyForm";
this.ResumeLayout(false);
}
private void MyForm_Load(object sender, System.EventArgs e)
{
//Image List を作成
imageListSmall = new ImageList();
//imageListSmall.ImageSize = new Size(16, 16);
for (int i = 0; i < Files.GetLength(0); i++)
{ imageListSmall.Images.Add(new Bitmap(Files[i])); }
listView1.SmallImageList = imageListSmall;
listView1.Items.Add("バラ");
listView1.Items.Add("ヒマワリ");
listView1.Items.Add("コスモス");
listView1.Items[0].ImageIndex = 0;
listView1.Items[1].ImageIndex = 1;
listView1.Items[2].ImageIndex = 2;
}
}
class form01
{
public static void Main()
{
MyForm mf = new MyForm();
Application.Run(mf);
}
}
|