C#中使comboBox下拉列表显示图片
来源:互联网 发布:2路视频加网络光端机 编辑:程序博客网 时间:2024/05/07 05:30
定义:
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.ImageList imageList1;
注意事项:
comboBox1下面两个属性一定要设为下面的值。
DrawMode:OwnerDrawFixed;
DropDownStyle:DropDownList;
DropDownStyle:DropDownList;
imageList1中一定要包函与所添加的项相同数目的图
关键方法:
此方法为comboBox1的DrawItem事件所引起的方法。
private void comboBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Graphics g = e.Graphics ;
Rectangle r = e.Bounds ;
Size imageSize = imageList1.ImageSize;
Font fn = null ;
if ( e.Index >= 0 )
{
fn = (Font)fontArray[0];
string s = (string)comboBox1.Items[e.Index];
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Near;
if ( e.State == ( DrawItemState.NoAccelerator | DrawItemState.NoFocusRect))
{
//画条目背景
e.Graphics.FillRectangle(new SolidBrush(Color.Red) , r);
//绘制图像
imageList1.Draw(e.Graphics, r.Left, r.Top,e.Index);
//显示字符串
e.Graphics.DrawString( s , fn , new SolidBrush(Color.Black), r.Left+imageSize.Width ,r.Top);
//显示取得焦点时的虚线框
e.DrawFocusRectangle();
}
else
{
e.Graphics.FillRectangle(new SolidBrush(Color.LightBlue) , r);
imageList1.Draw(e.Graphics, r.Left, r.Top,e.Index);
e.Graphics.DrawString( s , fn , new SolidBrush(Color.Black),r.Left+imageSize.Width ,r.Top);
e.DrawFocusRectangle();
}
}
{
Graphics g = e.Graphics ;
Rectangle r = e.Bounds ;
Size imageSize = imageList1.ImageSize;
Font fn = null ;
if ( e.Index >= 0 )
{
fn = (Font)fontArray[0];
string s = (string)comboBox1.Items[e.Index];
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Near;
if ( e.State == ( DrawItemState.NoAccelerator | DrawItemState.NoFocusRect))
{
//画条目背景
e.Graphics.FillRectangle(new SolidBrush(Color.Red) , r);
//绘制图像
imageList1.Draw(e.Graphics, r.Left, r.Top,e.Index);
//显示字符串
e.Graphics.DrawString( s , fn , new SolidBrush(Color.Black), r.Left+imageSize.Width ,r.Top);
//显示取得焦点时的虚线框
e.DrawFocusRectangle();
}
else
{
e.Graphics.FillRectangle(new SolidBrush(Color.LightBlue) , r);
imageList1.Draw(e.Graphics, r.Left, r.Top,e.Index);
e.Graphics.DrawString( s , fn , new SolidBrush(Color.Black),r.Left+imageSize.Width ,r.Top);
e.DrawFocusRectangle();
}
}
}
comboBox1.Items.Add("小车");
comboBox1.Items.Add("视频");
comboBox1.Items.Add("信号灯");
comboBox1.Items.Add("视频");
comboBox1.Items.Add("信号灯");
0 0
- C#中使comboBox下拉列表显示图片
- 如何实现ComboBox下拉列表显示图片
- 在combobox下拉列表中显示Treeview(转自csdn)
- c# Winform下拉列表框(ComboBox)中添加“其它”项
- C#中如何使ComboBox不能输入,只能从下拉列表中选择
- 在ComboBox下拉框数据中显示图片
- VC中ComboBox下拉列表不显示数据或下拉表高度太小的问题
- C# 实现ComboBox显示图片
- VC中ComboBox下拉列表不显示数据或只显示一行问题
- VC中ComboBox下拉列表不显示数据或只显示一行问题
- VBA 中COMBOBOX下拉列表的收起
- 使用下拉列表显示图片
- VB.Net程序设计:ComboBox下拉列表中显示多列数据-增加一个事件。
- VC中点击ComboBox下拉列表不显示数据的解决方法
- C#中怎么获取comboBox下拉列表选中项的Tag值
- C# 绘制ComboBox控件图片列表
- 下拉列表:comboBox控件
- ComboBox下拉列表
- Java 解决采集UTF-8网页空格变成问号乱码
- 标准I/O库与Unbuffered I/O(不带缓冲的I/O)函数
- 十几个方便实用的jquery代码
- Android内存性能优化(内部资料总结)
- Linux配置JDK环境变量
- C#中使comboBox下拉列表显示图片
- 第十四周项目一动物这样叫
- java反射机制实现实体遍历
- C++管理类的指针成员
- 使用mahout fpgrowth算法求关联规则
- #LeetCode 3Sum
- Resharper的快捷键
- ShareSDK分享遇到的问题及解决方法
- 关于QscrollArea的使用