解决方案 »
- winform中怎么根据权限让主菜单下的子菜单不可用(灰掉)
- 关于C#中XML的操作?
- Media Player 控件 播放器界面模式
- 请教:C#同时呼叫多支存储过程?
- 如何把一个.NET的DLL用命令行正确注册为COM的DLL库呢?
- 看到一些软件可以控制用户使用的时间,用户即使修改电脑时间也没有用!请教什么方法
- .net DataExcel通信组件使用 搭建简单文件服务器
- 在cs文件中调用JavaScript,但javascript却不能识别服务器端控件?
- 如何用winform程序登录网页
- 得到指定SQL SERVER 2003数据库中的表名???
- 求一代码 正则表达式解析字符串
- 一个网站,在VS2005正常运行,到iis就报错。
那个控件有其它地方不能满足我的需求。
没做过WINFORM的东西,刚才看了下编译的代码,在执行ONDRAMITEM时有个委托,还没看完。。
我画Items的时候,多画点儿东西就行了。重载相比自定义来说难度较低
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication17
{
using XX; public partial class Form1 : Form
{
public Form1()
{ InitializeComponent(); supListBox LB = new supListBox();
LB.Parent = this; Bitmap Bmp = new Bitmap(10, 10);
using (Graphics G = Graphics.FromImage(Bmp))
G.Clear(Color.Red); LB.Items.Add("AAA", Bmp);
}
} namespace XX
{
public static class X
{
/// <summary>
/// X
/// </summary>
/// <param name="OC">XX</param>
/// <param name="Obj">XXX</param>
/// <param name="Ic">XXXX</param>
public static void Add(this supListBox.ObjectCollection OC, Object Obj, Bitmap Bmp)
{
OC.Add(new ObjEx(Obj, Bmp));
}
}
} class ObjEx
{
public Object Obj;
public Bitmap Bmp; public ObjEx(Object Obj, Bitmap Bmp)
{
this.Obj = Obj;
this.Bmp = Bmp;
}
} public class supListBox : System.Windows.Forms.ListBox
{
public supListBox()
{
this.DrawMode = DrawMode.OwnerDrawFixed;
} protected override void OnDrawItem(DrawItemEventArgs e)
{
ObjEx Obj = (ObjEx)this.Items[e.Index];
Size S = TextRenderer.MeasureText(Obj.Obj.ToString(), this.Font); e.DrawBackground();
e.Graphics.DrawImage(Obj.Bmp, new Point(0, 0));
e.Graphics.DrawString(Obj.Obj.ToString(), this.Font, new SolidBrush(e.ForeColor),
new Point((e.Bounds.Width - S.Width) / 2, (e.Bounds.Height - S.Height) / 2));
}
}
}