先设置listBoxMsg.DrawMode = DrawMode.OwnerDrawFixed;

private void listBoxMsg_DrawItem(object sender, DrawItemEventArgs e)         {

ListBox lb= (ListBox)sender;

string s = lb.Items[e.Index].ToString();

if (s.Length * 15 > this.Width)

this.Width = s.Length * 15;

Brush myBrush = Brushes.Black;

Image image=null;//绘制图标

if (s.Contains("。"))

{

image = Image.FromFile(ResourceObj.DirectoryCurrent + "\\PIC\\Default\\error.png");

}

else

{

image = Image.FromFile(ResourceObj.DirectoryCurrent + "\\PIC\\Default\\excla.png");

}

//e.Graphics.FillRectangle(myBrush, e.Bounds);

//e.DrawFocusRectangle();//焦点框

Graphics g = e.Graphics;

Rectangle bounds = e.Bounds;

Rectangle imageRect = new Rectangle( bounds.X, bounds.Y-2, bounds.Height-4, bounds.Height-4);

Rectangle textRect = new Rectangle( imageRect.Right, bounds.Y, bounds.Width - imageRect.Right, bounds.Height);

if (image != null)

{

g.DrawImage(image,  imageRect,  0, 0,image.Width,image.Height, GraphicsUnit.Pixel);

}

//文本

StringFormat strFormat = new StringFormat();

strFormat.LineAlignment = StringAlignment.Near;

e.Graphics.DrawString(listBoxMsg.Items[e.Index].ToString(), e.Font, new SolidBrush(Color.FromArgb(0, 0, 0)), textRect, strFormat);

}

给ListBox每项加图标的更多相关文章

  1. volley+NetworkImageView实现列表界面的列表项中的左侧图标展现之【实现已经加载的列表项的图标上翻的时候不重新加载】

    参考资料:http://blog.csdn.net/guolin_blog/article/details/17482165 我使用的列表的适配器是继承ArrayAdapter的,所以关于使用voll ...

  2. 在C#中实现listbox的项上下移动(winform) 标准

      在C#中实现listbox的项上下移动(winform) 收藏人:梅毛子360   2013-10-02 | 阅:1  转:2  |  分享    |    来源              usi ...

  3. 刷新各ifream当前页,下拉项改变触发事件js,给选中项加背景色js

    <script type="text/javascript" language="javascript"> //刷新框架各页面 function r ...

  4. EXTJS 6 必填项加星号*

    /**重写ext filed组件, 实现表单必填项加红色*星号**/ Ext.override(Ext.form.field.Base,{ initComponent:function(){ if(t ...

  5. wpf listbox 选中项 上移下移

    原文:wpf listbox 选中项 上移下移 private void MoveUp_Click(object sender, RoutedEventArgs e)         {        ...

  6. vscode灰暗色主题和 左侧加图标 Spacegray VSCode vscode-icons

    vscode灰暗色主题和 左侧加图标 Spacegray VSCode vscode-icons

  7. Windows Phone 7 ListBox 列表项渐显加载动画学习笔记

    在wp7程序中,当程序功能越来越复杂时,性能问题是我们不得不考虑的一个问题.在聊天列表中,如果聊天项过多,而且项目UI组件足够复杂时, 我们不得不想尽办法让UI尽快加载.所以有一种可行的方案,就是像Q ...

  8. 实现Windows Phone 8中ListBox的分页加载

    功能就是ListBox滚动到最下方的时候,能够自动加载下一页的内容. 解决问题的关键就是如何判断ListBox已经加载到了最底部. 网上找了两个解决方法: 1 http://googlers.itey ...

  9. 【原创】小白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》连载五(给按钮加图标)

    在范例5-4所使用的导航栏中,已经为按钮加入了图标的样式,但是当时并没有介绍按钮的图标究竟是怎么一回事.下面截取范例5-4中导航栏部分的代码: <divdata-role="foote ...

随机推荐

  1. jQuery 菜单

  2. iOS第三方库管理工具

    作者:彷徨iOS 原文地址1:http://iostree.sinaapp.com/?p=78 原文地址2:http://blog.csdn.net/wzzvictory/article/detail ...

  3. Poj 1276 Cash Machine 多重背包

    Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26172   Accepted: 9238 Des ...

  4. Eclipse 恢复删除的文件

    这件事发生在,两周以前,那时我正在写LLT,补充完代码覆盖率.突然,我的代码呢,我的代码去哪里了?由于对Eclipse还不太熟悉,代码就则样被我从磁盘删掉了.然后火速给同事打电话,同事说如果删除了,而 ...

  5. Application Pool

  6. 用 正则表达式 限定XML simpleType 定义

    <xsd:simpleType name="ResTrictions"> <xsd:restriction base="xsd:string" ...

  7. iOS 解决图片上传到服务器旋转90度的问题(图片倒置)

    //使用swift的朋友们可以,把这个所在的类的.h,在-Header-Swift.h中一用一下. - (UIImage *)fixOrientation:(UIImage *)aImage { if ...

  8. 利用python检测色情图片简易实例

    import sys import os import _io from collections import namedtuple from PIL import Image class Nude( ...

  9. href="javascript:function()" 和onclick的区别

    href='javascript:function()'和onclick能起到同样的效果,一般来说,如果要调用脚本还是在onclick事件里面写代码,而不推荐在href='javascript:fun ...

  10. [linux系统]查看内核版本和系统版本方法

    查看内核版本信息的两个命令: uname -a cat /proc/version 查看系统版本的命令: lsb_release -a more /etc/issue cat /etc/redhat- ...