資源簡介
首先在窗體中添加一個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個文件信息
評論
共有 條評論