扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者: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); } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者