先设置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. UVALive 7148 LRIP(树的分治+STL)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

  2. struts2中的jsp值传到后台action接收的三种方法

    struts2中的Action接收表单传递过来的参数有3种方法: 如,登陆表单login.jsp: <form action="login" method="pos ...

  3. ubuntu配置tftp服务

    ubuntu配置TFTP服务: TFTP是用来下载远程文件的最简单的网络协议,基于UDP协议.xinetd是新一代的网络守护进程服务程序,经常用于管理多种轻量型internet服务. sudo apt ...

  4. Python对时间的转换

    1.将字符串的时间转换为时间戳 方法: a = "2013-10-10 23:40:00" 将其转换为时间数组 import time timeArray = time.strpt ...

  5. paper 132:图像去噪算法:NL-Means和BM3D

    这篇文章写的非常好,确定要~认真~慎重~的转载了,具体请关注本文编辑作者:http://wenhuix.github.io/research/denoise.html   我不会告诉你这里的代码都是f ...

  6. xhtml 和 html 的区别

    xhtml遵循xml文档规则,对于书写比较严格,相对于html来说,主要有以下不同: 标签不能重叠,可以嵌套标签与属性都要小写标签都要有始有终,要么以</p>形式结束,要么以<br ...

  7. js 一个自写的 监测类

    自从认识了jQuery后,很多页面加载入口,都放在document.ready里面.但是有时候这个觉得ready加载太慢, 这个[监测类 ]就开始产生了 效果类似这个. 每10毫秒检查一次,直到加载了 ...

  8. jQuery晦涩的底层工具方法们

    这里整理的是jQuery源码中一些比较晦涩难懂的.内部的.最底层的工具方法,它们多为jQuery的上层api方法服务,目前包括: jQuery.access jQuery.access: functi ...

  9. .net(C#)中结构和类的区别

    static void Main(string[] args) { //类型 //结构:值类型 //类:引用类型 //声明的语法:class struct //在类中,构造函数里,既可以给字段赋值,也 ...

  10. 使用httpclient发送http请求

    先来个httpclient的maven依赖 <dependency> <groupId>org.apache.httpcomponents</groupId> &l ...