扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:yzx110 来源:论坛 2007年11月13日
关键字:
private int _ImageIndex; public int ImageIndex { get { return this._ImageIndex; } set { this._ImageIndex = value;} } private Color _ForeColor; public Color ForeColor { get{ return this._ForeColor;} set { this._ForeColor = value; this.Parent.Invalidate(); } } |
private string _Text; public string Text { get { return this._Text; } set { this._Text = value; } } |
public override string ToString() { return this._Text; } |
private ListBoxExItemCollection _Items; //在构造函数中创建 |
new public ListBoxExItemCollection Items { get { return this._Items; } } new public ListBoxExItem SelectedItem //强制转换为ListBoxExItem { get{ return base.SelectedItem as ListBoxExItem;} set{ base.SelectedItem = value;} } new public SelectedListBoxExItemCollection SelectedItems //重新包装SelectedItems { get { return new SelectedListBoxExItemCollection(base.SelectedItems); } } |
private ImageList imageList; public ImageList ImageList { get { return this.imageList; } set { this.imageList = value; this.Invalidate();//图像列表改变后马上更新控件 } } |
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs pe) { pe.DrawBackground(); //画背景 pe.DrawFocusRectangle(); //画边框 Rectangle bounds = pe.Bounds; // Check whether the index is valid if(pe.Index >= 0 && pe.Index < base.Items.Count) { ListBoxExItem item = this.Items[pe.Index]; //取得需要绘制项的引用 int iOffset = 0; // If the image list is present and the image index is set, draw the image if(this.imageList != null) { if (item.ImageIndex > -1 && item.ImageIndex < this.imageList.Images.Count) { this.imageList.Draw(pe.Graphics, bounds.Left, bounds.Top, bounds.Height, bounds.Height, item.ImageIndex); //绘制图标 } iOffset += bounds.Height;//this.imageList.ImageSize.Width; } // Draw item text pe.Graphics.DrawString(item.Text, pe.Font, new SolidBrush(item.ForeColor),bounds.Left + iOffset, bounds.Top); //根据项的颜色绘制文本 } base.OnDrawItem(pe); } } |
婵犵數濮烽。浠嬪焵椤掆偓閸熷潡鍩€椤掆偓缂嶅﹪骞冨Ο璇茬窞闁归偊鍓涢悾娲⒑闂堟单鍫ュ疾濠婂嫭鍙忔繝濠傜墛閸嬨劍銇勯弽銊с€掗柟钘夊暣閺岀喖鎮滈埡鍌涚彋閻庤娲樺畝绋跨暦閸洖鐓涢柛灞剧矋濞堟悂姊绘担绛嬪殐闁搞劋鍗冲畷銏ゅ冀椤愩儱小闂佹寧绋戠€氼參宕伴崱妯镐簻闁靛牆鎳庢慨顒€鈹戦埥鍡椾簼婵犮垺锚铻炴俊銈呮噺閸嬪倹绻涢崱妯诲碍閻庢艾顦甸弻宥堫檨闁告挾鍠庨锝夘敆娓氬﹦鐭楁繛鎾村焹閸嬫捇鏌e☉娆愬磳闁哄本绋戦埞鎴﹀川椤曞懏鈻婄紓鍌欑劍椤ㄥ懘鎯岄崒鐐靛祦閹兼番鍔岄悞鍨亜閹烘垵顏╅悗姘槹閵囧嫰寮介妸褎鍣ョ紓浣筋嚙濡繈寮婚悢纰辨晣鐟滃秹鎮橀懠顒傜<閺夊牄鍔庣粻鐐烘煛鐏炶姤鍠橀柡浣瑰姍瀹曠喖顢橀悩铏钒闂備浇宕垫慨鎶芥⒔瀹ュ鍨傞柦妯猴級閿濆绀嬫い鏍ㄧ☉濞堟粓姊虹涵鍛【妞ゎ偅娲熼崺鈧い鎺嗗亾闁挎洩濡囧Σ鎰板籍閸繄顓洪梺缁樺姇瀵剙螖閸涱喚鍘搁梺鍓插亽閸嬪嫰鎮橀敃鍌涚厱閻庯綆鍋嗘晶顒傜磼閸屾稑绗ч柟鐟板閹煎湱鎲撮崟闈涙櫏闂傚倷绀侀幖顐も偓姘卞厴瀹曞綊鏌嗗鍛紱閻庡箍鍎遍ˇ浼村磿瀹ュ鐓曢柡鍥ュ妼婢ь垰霉閻樿秮顏堟箒闂佹寧绻傚Λ妤呭煝閺囥垺鐓冪憸婊堝礈濮樿泛钃熼柕濞у嫷鍋ㄩ梺缁樺姇椤曨參鍩㈤弴銏″€甸柨婵嗗€瑰▍鍥ㄣ亜韫囨稐鎲鹃柡灞炬礋瀹曢亶顢橀悢濂変紦