資源簡介
C#的ListView添加各種自定義控件,CheckBox,ComboBox等

代碼片段和文件信息
using?System;
using?System.Windows.Forms;
using?System.Drawing;
using?System.Collections;
namespace?test
{
????public?partial?class?EXComboBox?:?ComboBox
????{
????????private?Brush?_highlightbrush;?//color?of?highlighted?items
????????public?EXComboBox()
????????{
????????????_highlightbrush?=?SystemBrushes.Highlight;
????????????this.DrawMode?=?System.Windows.Forms.DrawMode.OwnerDrawVariable;
????????????this.DrawItem?+=?new?DrawItemEventHandler(this_DrawItem);
????????}
????????public?Brush?MyHighlightBrush
????????{
????????????get?{?return?_highlightbrush;?}
????????????set?{?_highlightbrush?=?value;?}
????????}
????????private?void?this_DrawItem(object?sender?DrawItemEventArgs?e)
????????{
????????????if?(e.Index?==?-1)?return;
????????????e.DrawBackground();
????????????if?((e.State?&?DrawItemState.Selected)?!=?0)
????????????{
????????????????e.Graphics.FillRectangle(_highlightbrush?e.Bounds);
????????????}
????????????EXItem?item?=?(EXItem)this.Items[e.Index];
????????????Rectangle?bounds?=?e.Bounds;
????????????int?x?=?bounds.X?+?2;
????????????if?(item.GetType()?==?typeof(EXImageItem))
????????????{
????????????????EXImageItem?imgitem?=?(EXImageItem)item;
????????????????if?(imgitem.MyImage?!=?null)
????????????????{
????????????????????Image?img?=?imgitem.MyImage;
????????????????????int?y?=?bounds.Y?+?((int)(bounds.Height?/?2))?-?((int)(img.Height?/?2))?+?1;
????????????????????e.Graphics.DrawImage(img?x?y?img.Width?img.Height);
????????????????????x?+=?img.Width?+?2;
????????????????}
????????????}
????????????else?if?(item.GetType()?==?typeof(EXMultipleImagesItem))
????????????{
????????????????EXMultipleImagesItem?imgitem?=?(EXMultipleImagesItem)item;
????????????????if?(imgitem.MyImages?!=?null)
????????????????{
????????????????????for?(int?i?=?0;?i?????????????????????{
????????????????????????Image?img?=?(Image)imgitem.MyImages[i];
????????????????????????int?y?=?bounds.Y?+?((int)(bounds.Height?/?2))?-?((int)(img.Height?/?2))?+?1;
????????????????????????e.Graphics.DrawImage(img?x?y?img.Width?img.Height);
????????????????????????x?+=?img.Width?+?2;
????????????????????}
????????????????}
????????????}
????????????int?fonty?=?bounds.Y?+?((int)(bounds.Height?/?2))?-?((int)(e.Font.Height?/?2));
????????????e.Graphics.DrawString(item.Text?e.Font?new?SolidBrush(e.ForeColor)?x?fonty);
????????????e.DrawFocusRectangle();
????????}
????????public?class?EXItem
????????{
????????????private?string?_text?=?““;
????????????private?string?_value?=?““;
????????????public?EXItem()
????????????{
????????????}
????????????public?EXItem(string?text)
????????????{
????????????????_text?=?text;
????????????}
????????????public?string?Text
????????????{
????????????????get?{?return?_text;?}
????????????????set?{?_text?=?value;?}
????????????}
????????????public?string?MyValue
????????????{
???????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????5470??2015-11-12?10:11??C#ListView中添加自定義控件\test\EXComboBox.cs
?????文件??????35259??2015-11-12?10:13??C#ListView中添加自定義控件\test\EXListView.cs
?????文件???????4183??2015-11-12?10:39??C#ListView中添加自定義控件\test\Form1.cs
?????文件???????3337??2015-11-12?10:27??C#ListView中添加自定義控件\test\Form1.Designer.cs
?????文件???????6017??2015-11-12?10:27??C#ListView中添加自定義控件\test\Form1.resx
?????文件????????485??2015-11-12?10:08??C#ListView中添加自定義控件\test\Program.cs
?????文件???????1358??2015-11-12?10:08??C#ListView中添加自定義控件\test\Properties\AssemblyInfo.cs
?????文件???????2860??2015-11-12?10:08??C#ListView中添加自定義控件\test\Properties\Resources.Designer.cs
?????文件???????5612??2015-11-12?10:08??C#ListView中添加自定義控件\test\Properties\Resources.resx
?????文件???????1091??2015-11-12?10:08??C#ListView中添加自定義控件\test\Properties\Settings.Designer.cs
?????文件????????249??2015-11-12?10:08??C#ListView中添加自定義控件\test\Properties\Settings.settings
?????文件???????3849??2015-11-12?10:14??C#ListView中添加自定義控件\test\test.csproj
?????文件????????854??2015-11-12?10:08??C#ListView中添加自定義控件\test.sln
????..A..H.?????20480??2015-11-12?10:27??C#ListView中添加自定義控件\test.suo
?????目錄??????????0??2018-01-15?14:39??C#ListView中添加自定義控件\test\bin
?????目錄??????????0??2015-11-12?10:08??C#ListView中添加自定義控件\test\Properties
?????目錄??????????0??2018-01-15?14:39??C#ListView中添加自定義控件\test
?????目錄??????????0??2018-01-15?14:38??C#ListView中添加自定義控件
-----------?---------??----------?-----??----
????????????????91104????????????????????18
- 上一篇:C#winfrom 音樂播放器源碼
- 下一篇:ArcEngine 時間滑塊功能
評論
共有 條評論