如何在下拉列表中的指定项加入图像和文本? 说到底就是自己Draw一个出来。onDrawItem时自己画出来就行了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 感谢您使用微软产品。您可以通过DrawItem和MeasureItem事件,来实现您的要求。下面,提供一个简单的示例程序供您参考,请根据您系统的实际情况进行相应的修改:1,设置ComboBox控件的DrawMode属性为:OwnerDrawFixed,这意味着加入的图象大小相同;如果设置该属性为OwnerDrawVariable,则需要编写MeasureItem事件。2,设置ComboBox控件的DropDownStyle属性为:DropDownList。示例代码如下:……private Font myFont;private String[] arr;private Image[] imageArr; ……public Form1(){ // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // myFont = new System.Drawing.Font("宋体",9); arr = new String[3]; arr[0] = "选项1"; arr[1] = "选项2"; arr[2] = "选项3"; this.comboBox1.DataSource = arr; imageArr = new Image[3]; imageArr[0] = new Bitmap("COPY.BMP"); imageArr[1] = new Bitmap("cut.bmp"); imageArr[2] = new Bitmap("help.bmp");}private void comboBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e){ e.Graphics.FillRectangle(Brushes.LightGreen ,e.Bounds); e.Graphics.DrawString(arr[e.Index],myFont,Brushes.Red,new Point(imageArr[e.Index].Width*2,e.Bounds.Y)); e.Graphics.DrawImage(imageArr[e.Index], new Point(e.Bounds.X,e.Bounds.Y)); if((e.State & DrawItemState.Focus) == 0) { e.Graphics.FillRectangle(Brushes.White, e.Bounds); e.Graphics.DrawString(arr[e.Index], myFont, Brushes.Blue, new Point(imageArr[e.Index].Width*2, e.Bounds.Y)); e.Graphics.DrawImage(imageArr[e.Index], new Point(e.Bounds.X,e.Bounds.Y)); }}关于ComboBox控件的更详细信息,请参考微软官方网站:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vboriComboBoxCtlTasks.asp — 微软全球技术中心 VB支持中心本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。 看SDK里的ComboBox的SAMPLE,有各种效果的源代码 菜鸟求各位解答??VS为什么按F5调试不了?? 如何在Form1.CS中点一个按钮,使Form2显示 C#字符串分割:字符串"AAABBBBCCFFFF"输出为"A3B4C2F4"怎么做? 最近想考个MCPD认证,各位大侠指导指导 c#中怎样实现字符全角半角转换 DataGrid中如何做所有頁統計? ASP.NET应用程序上如何实现树形,有没有这个控件? c#将图片上传到数据库怎么做 添加了一个NotifyIcon,但是我点击关闭的时候,并没有最小化到系统托盘 for循环中加入延时小程序,界面假死 事件、代表与事件方法 回答出来给100分
1,设置ComboBox控件的DrawMode属性为:OwnerDrawFixed,这意味着加入的图象大小相同;如果设置该属性为OwnerDrawVariable,则需要编写MeasureItem事件。
2,设置ComboBox控件的DropDownStyle属性为:DropDownList。
示例代码如下:
……
private Font myFont;
private String[] arr;
private Image[] imageArr;
……public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
myFont = new System.Drawing.Font("宋体",9); arr = new String[3];
arr[0] = "选项1";
arr[1] = "选项2";
arr[2] = "选项3"; this.comboBox1.DataSource = arr; imageArr = new Image[3];
imageArr[0] = new Bitmap("COPY.BMP");
imageArr[1] = new Bitmap("cut.bmp");
imageArr[2] = new Bitmap("help.bmp");
}private void comboBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
e.Graphics.FillRectangle(Brushes.LightGreen ,e.Bounds);
e.Graphics.DrawString(arr[e.Index],myFont,Brushes.Red,new Point(imageArr[e.Index].Width*2,e.Bounds.Y));
e.Graphics.DrawImage(imageArr[e.Index], new Point(e.Bounds.X,e.Bounds.Y)); if((e.State & DrawItemState.Focus) == 0)
{
e.Graphics.FillRectangle(Brushes.White, e.Bounds);
e.Graphics.DrawString(arr[e.Index], myFont, Brushes.Blue, new Point(imageArr[e.Index].Width*2, e.Bounds.Y));
e.Graphics.DrawImage(imageArr[e.Index], new Point(e.Bounds.X,e.Bounds.Y));
}
}关于ComboBox控件的更详细信息,请参考微软官方网站:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vboriComboBoxCtlTasks.asp
— 微软全球技术中心 VB支持中心本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。