给ListBox每项加图标
先设置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每项加图标的更多相关文章
- volley+NetworkImageView实现列表界面的列表项中的左侧图标展现之【实现已经加载的列表项的图标上翻的时候不重新加载】
参考资料:http://blog.csdn.net/guolin_blog/article/details/17482165 我使用的列表的适配器是继承ArrayAdapter的,所以关于使用voll ...
- 在C#中实现listbox的项上下移动(winform) 标准
在C#中实现listbox的项上下移动(winform) 收藏人:梅毛子360 2013-10-02 | 阅:1 转:2 | 分享 | 来源 usi ...
- 刷新各ifream当前页,下拉项改变触发事件js,给选中项加背景色js
<script type="text/javascript" language="javascript"> //刷新框架各页面 function r ...
- EXTJS 6 必填项加星号*
/**重写ext filed组件, 实现表单必填项加红色*星号**/ Ext.override(Ext.form.field.Base,{ initComponent:function(){ if(t ...
- wpf listbox 选中项 上移下移
原文:wpf listbox 选中项 上移下移 private void MoveUp_Click(object sender, RoutedEventArgs e) { ...
- vscode灰暗色主题和 左侧加图标 Spacegray VSCode vscode-icons
vscode灰暗色主题和 左侧加图标 Spacegray VSCode vscode-icons
- Windows Phone 7 ListBox 列表项渐显加载动画学习笔记
在wp7程序中,当程序功能越来越复杂时,性能问题是我们不得不考虑的一个问题.在聊天列表中,如果聊天项过多,而且项目UI组件足够复杂时, 我们不得不想尽办法让UI尽快加载.所以有一种可行的方案,就是像Q ...
- 实现Windows Phone 8中ListBox的分页加载
功能就是ListBox滚动到最下方的时候,能够自动加载下一页的内容. 解决问题的关键就是如何判断ListBox已经加载到了最底部. 网上找了两个解决方法: 1 http://googlers.itey ...
- 【原创】小白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》连载五(给按钮加图标)
在范例5-4所使用的导航栏中,已经为按钮加入了图标的样式,但是当时并没有介绍按钮的图标究竟是怎么一回事.下面截取范例5-4中导航栏部分的代码: <divdata-role="foote ...
随机推荐
- Java中String、StringBuffer、StringBuilder区别与理解
一.先比较String.StringBuffer.StringBuilder变量的HashCode值 使用System.out.println(obj.hashcode())输出的时对象的哈希码, 而 ...
- IT girl
听着柔和的音乐,敲着自己喜欢的代码......
- Android studio 中的配置编译错误总结
1.编译Andorid 工程的时候,有时候出现gradle 报下面的错误. Error:(1, 0) Cause: com/android/build/gradle/LibraryPlugin : U ...
- nfc相关
nfc普通读卡写卡按厂商API操作即可,但是牵扯到NDEF的读写就另当别论了,算是二次开放了,android手机有成熟的接口,.net也有一些,github上有一个,还没研究, https://git ...
- Fortran 基础语法(一)
GE是大于等于号(>=),GT是大于号(>),LE是小于等于号(<=),LT是小于号(<) IF基本用法 If(逻辑判断式) then …… End if If(逻辑判断式 ...
- Cellebrite UFED 5.1 发布,全面支持三星 S6 S6 Edge Note5 HUAWEI series
世界级取证公司Cellebrite 昨天发布了最新的 UFED 5.1 系统更新,4PC全面支持三星S6,S6EDGE NOTE5 以及HUAWEI,LG系列恢复,锁屏密码XX!下面是部分截图 有需要 ...
- 干货——myeclipse快捷键
好了废话不多说.先上快捷键快捷键 alt alt+ 返回操作记录的上一步 alt+ 返回操作记录的下一步 alt+shift+o 同一 ...
- ios 使用AFN上传图片到服务器
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSe ...
- jquery autocomplete
<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="http: ...
- c++错误——intermediate.manifest : general error c1010070很傻的错
.\Debug\sadf.exe.intermediate.manifest : general error c1010070: Failed to load and parse the manife ...