如何设置ListView的SubItem图标? http://www.codeproject.com/dotnet/msgaddin.asp?target=listview这里那么多listView,应该能找到个类似的吧:http://www.codeproject.com/cs/miscctrl/#ListView+controls 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以没有问题using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace ListBoxWithIcon{ /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { private GListBox lb; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { ImageList imageList = new ImageList(); imageList.Images.Add(Image.FromFile(@"D:\我的文件\myrice\favicon.ico")); imageList.Images.Add(Image.FromFile(@"D:\我的文件\myrice\favicon4.ico")); imageList.Images.Add(Image.FromFile(@"D:\我的文件\myrice\favicon5.ico")); this.lb = new GListBox();; this.SuspendLayout(); // // lb // this.lb.ItemHeight = 16; this.lb.Location = new System.Drawing.Point(10, 10); this.lb.Name = "listBox1"; this.lb.Size = new System.Drawing.Size(200, 60); this.lb.TabIndex = 0; lb.ImageList = imageList; lb.Items.Add( new GListBoxItem("http://xml.sz.luohuedu.net/",0)); lb.Items.Add( new GListBoxItem("http://lucky.myrice.com/",1)); lb.Items.Add( new GListBoxItem("【孟宪会之精彩世界】",2)); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 160); this.Controls.Add(this.lb); this.Text = "带图标的ListBox测试"; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { } // GListBoxItem 类 public class GListBoxItem { private string _myText; private int _myImageIndex; // 属性 public string Text { get {return _myText;} set {_myText = value;} } public int ImageIndex { get {return _myImageIndex;} set {_myImageIndex = value;} } //构造函数 public GListBoxItem(string text, int index) { _myText = text; _myImageIndex = index; } public GListBoxItem(string text): this(text,-1){} public GListBoxItem(): this(""){} public override string ToString() { return _myText; } } // GListBox 类 public class GListBox : ListBox { private ImageList _myImageList; public ImageList ImageList { get {return _myImageList;} set {_myImageList = value;} } public GListBox() { this.DrawMode = DrawMode.OwnerDrawFixed; } protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { e.DrawBackground(); e.DrawFocusRectangle(); GListBoxItem item; Rectangle bounds = e.Bounds; Size imageSize = _myImageList.ImageSize; try { item = (GListBoxItem) Items[e.Index]; if (item.ImageIndex != -1) { ImageList.Draw(e.Graphics, bounds.Left,bounds.Top,item.ImageIndex); e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor), bounds.Left+imageSize.Width, bounds.Top); } else { e.Graphics.DrawString(item.Text, e.Font,new SolidBrush(e.ForeColor), bounds.Left, bounds.Top); } } catch { if (e.Index != -1) { e.Graphics.DrawString(Items[e.Index].ToString(),e.Font, new SolidBrush(e.ForeColor) ,bounds.Left, bounds.Top); } else { e.Graphics.DrawString(Text,e.Font,new SolidBrush(e.ForeColor), bounds.Left, bounds.Top); } } base.OnDrawItem(e); } } }} 求助!C#中提交后总是提示失败!急! 对于某些汉字的utf8编码用gb2312解码后无法还原的请教 新浪微博的地址加密方式是什么? C# lock 关键字 在VC++ 中如何实现的? 相对位置绝对位置 高分求教C#获取文件夹路径问题 请大家帮忙一下,我这个程序的思路有点不对,不知道怎么去分析!!,跪 求之中。。。 关于DataGrid的一个小问题 高分提问:vs2003 winform datagrid 如何自动高亮显示当前光标所在行? 高分相送:请问哪里有C#软件下载(已解密) 急用!!!!!! C#中有没有象VB中的CHR这样的函数?
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace ListBoxWithIcon
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private GListBox lb;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
ImageList imageList = new ImageList();
imageList.Images.Add(Image.FromFile(@"D:\我的文件\myrice\favicon.ico"));
imageList.Images.Add(Image.FromFile(@"D:\我的文件\myrice\favicon4.ico"));
imageList.Images.Add(Image.FromFile(@"D:\我的文件\myrice\favicon5.ico")); this.lb = new GListBox();;
this.SuspendLayout();
//
// lb
//
this.lb.ItemHeight = 16;
this.lb.Location = new System.Drawing.Point(10, 10);
this.lb.Name = "listBox1";
this.lb.Size = new System.Drawing.Size(200, 60);
this.lb.TabIndex = 0; lb.ImageList = imageList;
lb.Items.Add( new GListBoxItem("http://xml.sz.luohuedu.net/",0));
lb.Items.Add( new GListBoxItem("http://lucky.myrice.com/",1));
lb.Items.Add( new GListBoxItem("【孟宪会之精彩世界】",2)); //
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 160);
this.Controls.Add(this.lb);
this.Text = "带图标的ListBox测试";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{
} // GListBoxItem 类
public class GListBoxItem
{
private string _myText;
private int _myImageIndex;
// 属性
public string Text
{
get {return _myText;}
set {_myText = value;}
}
public int ImageIndex
{
get {return _myImageIndex;}
set {_myImageIndex = value;}
}
//构造函数
public GListBoxItem(string text, int index)
{
_myText = text;
_myImageIndex = index;
}
public GListBoxItem(string text): this(text,-1){}
public GListBoxItem(): this(""){}
public override string ToString()
{
return _myText;
}
} // GListBox 类
public class GListBox : ListBox
{
private ImageList _myImageList;
public ImageList ImageList
{
get {return _myImageList;}
set {_myImageList = value;}
}
public GListBox()
{
this.DrawMode = DrawMode.OwnerDrawFixed;
}
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
{
e.DrawBackground();
e.DrawFocusRectangle();
GListBoxItem item;
Rectangle bounds = e.Bounds;
Size imageSize = _myImageList.ImageSize;
try
{
item = (GListBoxItem) Items[e.Index];
if (item.ImageIndex != -1)
{
ImageList.Draw(e.Graphics, bounds.Left,bounds.Top,item.ImageIndex);
e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor),
bounds.Left+imageSize.Width, bounds.Top);
}
else
{
e.Graphics.DrawString(item.Text, e.Font,new SolidBrush(e.ForeColor),
bounds.Left, bounds.Top);
}
}
catch
{
if (e.Index != -1)
{
e.Graphics.DrawString(Items[e.Index].ToString(),e.Font,
new SolidBrush(e.ForeColor) ,bounds.Left, bounds.Top);
}
else
{
e.Graphics.DrawString(Text,e.Font,new SolidBrush(e.ForeColor),
bounds.Left, bounds.Top);
}
}
base.OnDrawItem(e);
}
}
}
}