资源简介
首先在窗体中添加一个comboBox1和一个imageList(本例中带有三个图片)
this.comboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace shishi2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
comboBox1.DrawMode = DrawMode.OwnerDrawFixed;
comboBox1.DropDownstyle = ComboBoxstyle.DropDownList;
comboBox1.Items.Add(“小车“);
comboBox1.Items.Add(“视频“);
comboBox1.Items.Add(“信号灯“);
}
private void comboBox1_DrawItem(object sender DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Rectangle r = e.Bounds;
Size imageSize = imageList1.ImageSize;
if (e.Index >= 0)
{
Font fn = new Font(“Tahoma“ 10 Fontstyle.Bold);
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();
}
}
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 12800 2010-08-20 09:03 shishi2\shishi2\bin\Debug\shishi2.exe
文件 19968 2010-08-20 09:03 shishi2\shishi2\bin\Debug\shishi2.pdb
文件 11600 2010-08-20 09:03 shishi2\shishi2\bin\Debug\shishi2.vshost.exe
文件 490 2010-03-17 22:39 shishi2\shishi2\bin\Debug\shishi2.vshost.exe.manifest
文件 2175 2010-08-20 09:03 shishi2\shishi2\Form1.cs
文件 2858 2010-08-20 09:00 shishi2\shishi2\Form1.Designer.cs
文件 10007 2010-08-20 09:00 shishi2\shishi2\Form1.resx
文件 2152 2010-08-20 08:58 shishi2\shishi2\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6163 2010-08-20 09:03 shishi2\shishi2\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 172 2010-08-20 09:00 shishi2\shishi2\obj\x86\Debug\GenerateResource.read.1.tlog
文件 442 2010-08-20 09:00 shishi2\shishi2\obj\x86\Debug\GenerateResource.write.1.tlog
文件 526 2010-08-20 09:03 shishi2\shishi2\obj\x86\Debug\shishi2.csproj.FileListAbsolute.txt
文件 12800 2010-08-20 09:03 shishi2\shishi2\obj\x86\Debug\shishi2.exe
文件 2937 2010-08-20 09:00 shishi2\shishi2\obj\x86\Debug\shishi2.Form1.resources
文件 19968 2010-08-20 09:03 shishi2\shishi2\obj\x86\Debug\shishi2.pdb
文件 180 2010-08-20 09:00 shishi2\shishi2\obj\x86\Debug\shishi2.Properties.Resources.resources
文件 488 2010-08-20 08:58 shishi2\shishi2\Program.cs
文件 1346 2010-08-20 08:58 shishi2\shishi2\Properties\AssemblyInfo.cs
文件 2862 2010-08-20 08:58 shishi2\shishi2\Properties\Resources.Designer.cs
文件 5612 2010-08-20 08:58 shishi2\shishi2\Properties\Resources.resx
文件 1090 2010-08-20 08:58 shishi2\shishi2\Properties\Settings.Designer.cs
文件 249 2010-08-20 08:58 shishi2\shishi2\Properties\Settings.settings
文件 3673 2010-08-20 09:00 shishi2\shishi2\shishi2.csproj
文件 863 2010-08-20 08:58 shishi2\shishi2.sln
..A..H. 17920 2010-08-20 09:14 shishi2\shishi2.suo
目录 0 2010-08-20 08:58 shishi2\shishi2\obj\x86\Debug\TempPE
目录 0 2010-08-20 09:03 shishi2\shishi2\obj\x86\Debug
目录 0 2010-08-20 09:03 shishi2\shishi2\bin\Debug
目录 0 2010-08-20 08:58 shishi2\shishi2\obj\x86
目录 0 2010-08-20 08:58 shishi2\shishi2\bin
............此处省略7个文件信息
相关资源
- Visio图标-最新最全的网络通信图标库
- 最新版TTF16.OCX Formula One v. 6.1.6.2 控件
- 隐藏任务栏图标工具(hot)
- PB做的托盘程序(最小化后在左下角显
- 可拖拽的甘特图控件(完整)
- 一个扩展的CComboBox 下拉框 自绘 美化
- QRMaker.ocx控件
- MFC控件动态拖动
- 可编辑的CListctrl 支持CEDIT文本框,C
- js实现的日历控件(经典好用)
- 上传大文件并显示进度条控件实例
- 组态王6.53树形控件实例
- 用FileSystemWatcher控件实现文件同步更新
- 毕业设计:网络围棋对弈
- 自定义的TabCtrl控件实现
- 文件夹图标修改器.bat
- RadioButton控件
- “猜数字”游戏 算法破解
- OpenGL-3D坦克模拟
- 在delphi7下进行autocad二次开发的一个简
- powerdatagrid控件 源码
- 采用WINSOCK2 编写的TCP/UDP通信程序
- 大陆天堂2原代码
- PB做的俄罗斯方块
- animatedgif
- 典当综合业务管理系统(完整版)
- 图像处理作业C 源代码
- 联机版井字棋源码
- 用IdFTPServer写的一个FTPServer程序
- 视频处理控件TVideoGrabber.v6.7.5.For.Del
评论
共有 条评论