欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
為ComboBox控件添加圖片
作者:孟憲會(huì ) 發(fā)表于:2003-07-02 17:34:04

.NET自帶的ComboBox控件沒(méi)有添加圖片的功能,我們可以自己進(jìn)行擴展,下面就是擴展類(lèi)的代碼:

結果如下:

ComboBoxEx.cs

using System;using System.Windows.Forms;using System.Windows.Forms.Design;using System.Drawing;namespace Mengxianhui.ComboBoxEx{class ComboBoxEx : ComboBox{private ImageList imageList;public ImageList ImageList{get {return imageList;}set {imageList = value;}}public ComboBoxEx(){DrawMode = DrawMode.OwnerDrawFixed;}protected override void OnDrawItem(DrawItemEventArgs ea){ea.DrawBackground();ea.DrawFocusRectangle();ComboBoxExItem item;Size imageSize = imageList.ImageSize;Rectangle bounds = ea.Bounds;try{item = (ComboBoxExItem)Items[ea.Index];if (item.ImageIndex != -1){imageList.Draw(ea.Graphics, bounds.Left, bounds.Top,item.ImageIndex);ea.Graphics.DrawString(item.Text, ea.Font, newSolidBrush(ea.ForeColor), bounds.Left+imageSize.Width, bounds.Top);}else{ea.Graphics.DrawString(item.Text, ea.Font, newSolidBrush(ea.ForeColor), bounds.Left, bounds.Top);}}catch{if (ea.Index != -1){ea.Graphics.DrawString(Items[ea.Index].ToString(), ea.Font, newSolidBrush(ea.ForeColor), bounds.Left, bounds.Top);}else{ea.Graphics.DrawString(Text, ea.Font, newSolidBrush(ea.ForeColor), bounds.Left, bounds.Top);}}base.OnDrawItem(ea);}}class ComboBoxExItem{private string _text;public string Text{get {return _text;}set {_text = value;}}private int _imageIndex;public int ImageIndex{get {return _imageIndex;}set {_imageIndex = value;}}public ComboBoxExItem(): this(""){}public ComboBoxExItem(string text): this(text, -1){}public ComboBoxExItem(string text, int imageIndex){_text = text;_imageIndex = imageIndex;}public override string ToString(){return _text;}}}

使用方法

using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace Mengxianhui.ComboBoxEx{/// <summary>/// Summary description for Form1./// </summary>public class Form1 : System.Windows.Forms.Form{private ComboBoxEx comboBox1;private System.ComponentModel.IContainer components;public Form1(){//// Required for Windows Form Designer support//InitializeComponent();//// TODO: Add any constructor code after InitializeComponent call//}/// <summary>/// Clean up any resources being used./// </summary>protected override void Dispose( bool disposing ){if( disposing ){if (components != null){components.Dispose();}}base.Dispose( disposing );}#region Windows Form Designer generated code/// <summary>/// Required method for Designer support - do not modify/// the contents of this method with the code editor./// </summary>private void InitializeComponent(){ComboBoxEx comboBox1 = new ComboBoxEx();ImageList imageList1 = new ImageList();imageList1.Images.Add(Image.FromFile(@"D:\favicon.ico"));imageList1.Images.Add(Image.FromFile(@"D:\favicon4.ico"));imageList1.Images.Add(Image.FromFile(@"D:\favicon5.ico"));comboBox1.ImageList = imageList1;comboBox1.Width = 200;comboBox1.Items.Add(new ComboBoxExItem("【孟憲會(huì )之精彩世界】", 0));comboBox1.Items.Add(new ComboBoxExItem("【孟憲會(huì )之精彩世界】", 1));comboBox1.Items.Add(new ComboBoxExItem("【孟憲會(huì )之精彩世界】", 2));this.Controls.AddRange(new System.Windows.Forms.Control[] {comboBox1});//// Form1//this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);this.ClientSize = new System.Drawing.Size(292, 273);this.Controls.AddRange(new System.Windows.Forms.Control[] {comboBox1});this.Name = "Form1";this.Text = "Form1";this.ResumeLayout(false);}#endregion/// <summary>/// The main entry point for the application./// </summary>[STAThread]static void Main(){Application.Run(new Form1());}}}
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
一步一步玩控件:自定義TabControl
C# ListView用法詳解
Extended ComboBox添加圖標
c# 中treeview 樹(shù)節點(diǎn)圖標的動(dòng)態(tài)加載,及選中時(shí)圖標改變
如何在 C#中的listView 控件中顯示圖片?
Winform重繪ComboBox背景
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久