winform listbox 使用DrawMode使用OwnerDrawVarialbe或OwnerDrawFixed无水平滚动条
因为需要使用DrawMode自行DrawItem,所以需要将DrawMode设置为OwnerDrawVarialbe或OwnerDrawFixed模式,代码如下:
private void listBox_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index >= 0)
{
e.DrawBackground();
Brush mybsh = Brushes.Black;
if (listBox4.Items[e.Index].ToString().IndexOf("[ERROR]") != -1)
{
mybsh = Brushes.Red;
}
// 焦点框
e.DrawFocusRectangle();
//文本
//e.Graphics.DrawString(listBox4.Items[e.Index].ToString(), e.Font, mybsh, e.Bounds, StringFormat.GenericDefault);
e.Graphics.DrawString(listBox4.Items[e.Index].ToString(), e.Font, mybsh, e.Bounds, null);
}
}
并对listbox增加事件:DrawItem事件设置为listBox_DrawItem
但是这样就无法使用默认方式出现水平滚动条,那么需要对listbox增加事件listbox_MeasureItem,代码如下:
private void listBox_MeasureItem(object sender, MeasureItemEventArgs e)
{
String lvsDisp = listBox.Items[e.Index].ToString();
SizeF lvSize = e.Graphics.MeasureString(lvsDisp, listBox.Font);
if (listBox.HorizontalExtent < lvSize.Width)
{
listBox.HorizontalExtent = (int)lvSize.Width + 10;
}
e.ItemHeight = (int)lvSize.Height;
e.ItemWidth = (int)lvSize.Width;
}
这样就可以自动出现水平滚动条了。
winform listbox 使用DrawMode使用OwnerDrawVarialbe或OwnerDrawFixed无水平滚动条的更多相关文章
- C# winform listBox中的项上下移动(转)
C# winform listBox中的项上下移动 分类: C# winform2009-06-24 12:37 876人阅读 评论(0) 收藏 举报 winformc#object //上移节点 ...
- 发掘ListBox的潜力(一):自动调整横向滚动条宽度
<自绘ListBox的两种效果>一文帖出之后,从反馈信息来看,大家对这种小技巧还是很认同.接下来我将继续围绕ListBox写一系列的文章,进一步发掘ListBox的潜力,其中包括:自动调整 ...
- 为MFC中的ListBox添加水平滚动条
我们知道,MFC中的水平滚动条并不像垂直滚动条那样的智能.当文字超出ListBox的宽度时,水平滚动条并不会自己出现,我们需要手动的调用CListBox中的函数SetHorizontalExtent设 ...
- (七)对话框,单选框(radiobox),复选框(checkbox),列表框(ListBox),组合框(CComboBox),水平滚动条(Horizontal scroll bar),微调(旋转)spincontrol,列表视图控件CListCtrl,静态控件static
1,模态对话框和非模态对话框 // 模态对话框 void CMainFrame::OnDialogExec() { // TODO: 在此添加命令处理程序代码 // 创建对话框对象 CDialog d ...
- C# winform Listbox添加和删除items
两个listbox添加和删除items #region 添加/移除 //添加 private void btnAdd_Click(object sender, EventArgs e) { ) { r ...
- C# winform ListBox实现滚动条自动滚动至底部
效果如图: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data ...
- winform listbox增加鼠标双击事件
在Form.Designer.cs文件中对于listBox处理: listBox.MouseDoubleClick += new system.Windows.Forms.MouseEventHand ...
- WinForm ListBox 控件用法
下面演示如何利用列表控件 ListBox 实现多选与移动选项: using IMS.WinFormClient.UserControls; using System; using System.Col ...
- Winform ListBox输出信息并自动滚动至底部
应用场景:ListBox作为软件信息的输出框. //ListBox输出信息 internal void SetListBoxMessage(string str) { if (this.Message ...
随机推荐
- Java之集合(十)EnumMap
转载请注明源出处:http://www.cnblogs.com/lighten/p/7371744.html 1.前言 本章介绍Map体系中的EnumMap,该类是专门针对枚举类设计的一个集合类.集合 ...
- js前端日期格式化处理
js前端日期格式化处理 1.项目中时间返回值,很过时候为毫秒值,我们需要转换成 能够看懂的时间的格式: 例如: yyyy-MM-dd HH:mm:ss 2.处理方法(处理方法有多种,可以传值到前端 ...
- Android4.0 Launcher 源码分析2——Launcher内容加载绑定详细过程
Launcher在应用启动的时候,需要加载AppWidget,shortcut等内容项,通过调用LauncherModel.startLoader(),开始加载的工作.launcherModel中加载 ...
- ambari 2.6.2 安装 hdp 2.6.5.0 遇到的问题
1.hive-client 无法安装 一直报错(symlink target already exists and it is not a symlink.),hive-client 已经存在且不是 ...
- Mysql 断电数据损毁恢复
error log: Database page corruption on disk or a failed 处理: /etc/my.cnf 设置 innodb_force_recovery = 6 ...
- 仿制淘宝sku点击效果
1.依赖jquery,主要利用二维数组. 2.原生手写. 代码如下: <!DOCTYPE html> <html> <head> <meta charset= ...
- CentOS SVN Failed to load JavaHL Library
在CentOS 6上的eclipse安装了svbclipse插件后,svn不能使用,并且第一次使用的时候还出现下面错误窗口提示 Failed to load JavaHL Library. These ...
- Cacheable redis 宕机
使用Cacheable注解Redis方法时,如果Redis服务器挂了,就直接抛出异常了, java.net.ConnectException: Connection refused: connect ...
- JBoss Web和Tomcat的区别
在Web2.0的时代,基于Tomcat内核的JBoss在J2EE应用服务器领域已成为发展最为迅速的应用服务器.这一青出于蓝而胜于蓝的产品与Tomcat的区别又在哪里? 基于Tomcat内核,青胜于蓝. ...
- 一张图解决Struts2添加源码
主要是选择的路径:F:/struts2/struts-2.3.31/src/core/src/main/java