ListBox重绘
.NET Framework 类库 ListBox.ItemHeight 属性
当 DrawMode 属性设置为 DrawMode.OwnerDrawFixed 时,所有项具有相同的高度。当 DrawMode 属性设置为 DrawMode.OwnerDrawVariable 时,ItemHeight 属性指定添加到 ListBox 中的每个项的高度。因为所有者描述的列表中的每个项可具有不同的高度,所以可使用 GetItemHeight 方法获取 ListBox 中特定项的高度。如果对具有可变高度的项的 ListBox 使用 ItemHeight 属性,则此属性返回控件中第一个项的高度。
ListBox 项的最大高度是 255 像素。

listbox每行的文字名称重绘
http://files.cnblogs.com/xe2011/CSharpListBoxDrawItem.rar
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
//添加字体
foreach (FontFamily fam in FontFamily.Families)
{
listBox1.Items.Add(fam.Name);
} //OwnerDrawVariable
listBox1.DrawMode = DrawMode.OwnerDrawVariable;
} private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
//e.DrawFocusRectangle();
e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), new Font(listBox1.Items[e.Index].ToString(), ), Brushes.Black, e.Bounds);
} private void listBox1_MeasureItem(object sender, MeasureItemEventArgs e)
{
e.ItemHeight =;
}
}
}

ListBoxbox1的每行的行高
http://files.cnblogs.com/xe2011/CSharpListBoxDrawItemHeight.rar
private void Form1_Load(object sender, EventArgs e)
{
//OwnerDrawVariable
listBox1.DrawMode = DrawMode.OwnerDrawVariable;
} private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
//e.DrawFocusRectangle(); string s= listBox1.Items[e.Index].ToString();
int fontSize = Convert.ToInt32( listBox1.Items[e.Index].ToString() );
Font font =new Font("Times New Roman", fontSize, FontStyle.Bold); e.Graphics.DrawString(s, font, Brushes.Black, e.Bounds);
} private void listBox1_MeasureItem(object sender, MeasureItemEventArgs e)
{
e.ItemHeight = Convert.ToInt32(listBox1.Items[e.Index].ToString())+;
}
Combobox的和ListBox的写法一样
Combobox 文字名称http://files.cnblogs.com/xe2011/CSharpComboboxDrawItem.rar
private void Form1_Load(object sender, EventArgs e)
{
////添加字体
foreach (FontFamily f in FontFamily.Families)
{
comboBox1.Items.Add(f.Name);
} //OwnerDrawVariable
comboBox1.DrawMode = DrawMode.OwnerDrawVariable;
comboBox1.MaxDropDownItems = ;
comboBox1.DropDownWidth = ;
} private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
//e.DrawFocusRectangle();
string s = comboBox1.Items[e.Index].ToString();
string fontName = comboBox1.Items[e.Index].ToString();
Font font = new Font(fontName, );
e.Graphics.DrawString(s, font, Brushes.Black, e.Bounds);
} private void comboBox1_MeasureItem(object sender, MeasureItemEventArgs e)
{
e.ItemHeight = ;
}
Combobox文字行高

附件http://files.cnblogs.com/xe2011/CSharpComboboxDrawItemHeight.rar
private void Form1_Load(object sender, EventArgs e)
{
this.comboBox1.Items.AddRange(new string[] {
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""}); //OwnerDrawVariable
comboBox1.DrawMode = DrawMode.OwnerDrawVariable;
comboBox1.MaxDropDownItems = ;
comboBox1.DropDownWidth = ; } private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{ e.DrawBackground();
//e.DrawFocusRectangle(); string s = comboBox1.Items[e.Index].ToString();
int fontSize = Convert.ToInt32(comboBox1.Items[e.Index].ToString());
Font font = new Font("Times New Roman", fontSize, FontStyle.Bold); e.Graphics.DrawString(s, font, Brushes.Black, e.Bounds);
} private void comboBox1_MeasureItem(object sender, MeasureItemEventArgs e)
{
e.ItemHeight = Convert.ToInt32(comboBox1.Items[e.Index].ToString()) + ;
}
ListBox重绘的更多相关文章
- uCGUI窗口重绘代码分析
一.概述 µC/GUI的窗口重绘是学习者理解窗口工作原理和应用窗口操作的重点.µC/GUI的窗口重绘引入了回调机制,回调机制可以实现图形系统调用用户的代码,由于图形系统使用了剪切算法,使得屏幕重绘的效 ...
- 深入Windows窗体原理及控件重绘技巧
之前有学MFC的同学告诉我觉得Windows的控件重绘难以理解,就算重绘成功了还是有些地方不明白,我觉得可能很多人都有这样的问题,在这里我从Windows窗体的最基本原理来讲解,如果你有类似的疑惑希望 ...
- VC++中关于控件重绘函数/消息 OnPaint,OnDraw,OnDrawItem,DrawItem的区别
而OnPaint()是CWnd的类成员,同时负责响应WM_PAINT消息. OnDraw()是CVIEW的成员函数,并且没有响应消息的功能.这就是为什么你用VC成的程序代码时,在视图类只有OnDraw ...
- 使用重绘项美化WinForm中的控件
如果你觉得项目中的ComboBox.ListBox或其它的Winforms控件不能满足你的显示要求,包括窗体在内很多控件都支持重绘修改显示样式.下面的示例完成对ComBox数据项的重绘,希望能起到抛砖 ...
- 关于DOM的操作以及性能优化问题-重绘重排
写在前面: 大家都知道DOM的操作很昂贵. 然后贵在什么地方呢? 一.访问DOM元素 二.修改DOM引起的重绘重排 一.访问DOM 像书上的比喻:把DOM和JavaScript(这里指ECMScri ...
- 关于repaint(重绘)和reflow( 回流)
repaint就是重绘,reflow就是回流.repaint主要是针对某一个DOM元素进行的重绘,reflow则是回流,针对整个页面的重排 严重性: 在性能优先的前提下,性能消耗 reflow大于re ...
- MFC 滑动条的重绘
MFC自带的滑动条的样子是这样的. 比较难看,所以需要重绘下,重绘后的样子是这样的. 代码如下: CustomSliderCtr.h #pragma once // CCustomSliderCtr ...
- WinForm中重绘TabControl选项卡标题
最近开发WinForm频繁使用了TabControl控件,这个控件的选项卡没有BackgroundImage这个属性,那么如何为其各个选项卡添加背景图片呢?(这里说的是每个TabPage的头部,也就是 ...
- 回流(reflow)与重绘(repaint)
最近项目排期不紧,于是看了一下之前看了好久也没看明白的chrome调试工具的timeline.但是很遗憾,虽然大概懂了每一项是做什么的,但是用起来并不能得心应手.所以今天的重点不是timeline,而 ...
随机推荐
- Java NIO回炉
重回东软了,据说可能要做一个跟文件相关的项目,于是决定把Java NIO的内容再捡起来,看看. 为什么要使用NIO,其实在低连接数的情况下,NIO的性能是要低于IO的:但是在高并发的情况下,确实NIO ...
- 安装pip之后,执行pip,提示:unknown or unsupported command install
安装pip之后,在dos命令框中输入pip,提示:unknown or unsupported command install,搜索之后,立马在:http://stackoverflow.com/qu ...
- JNI/NDK开发指南(开山篇)
转载请注明出处:http://blog.csdn.net/xyang81/article/details/41759643 相信很多做过Java或Android开发的朋友经常会接触到JNI方面的技术, ...
- 计算几何模板 (bzoj 1336,poj 2451 ,poj3968)
poj 3968 (bzoj 2642) 二分+半平面交,每次不用排序,这是几个算几版综合. #include<iostream> #include<cstdio> #incl ...
- 使用jxl.jar操作Excel
在工程的build path中添加jxl.jar,网址:http://www.andykhan.com/jexcelapi/ import java.io.BufferedReader; import ...
- Eclipse下设置github开发环境
1.按照github上的指南配置(http://help.github.com/win-set-up-git/)基础的git环境. 2.在github上创建一个Repository. 3.在Eclip ...
- perl unload gbk oracle 数据库
perl unload gbk Oracle 数据库 use Encode; if ( $#ARGV < 0 ){ print "请输入一个文件\n"; exit(-1); ...
- hadoop多机安装HA+YARN
HA 相比于Hadoop1.0,Hadoop 2.0中的HDFS增加了两个重大特性,HA(热备)和Federation(联邦).HA即为High Availability,用于解决NameNode单点 ...
- Linux 下报错:A Java RunTime Environment (JRE) or Java Development Kit (JDK) must解决方案
一.报错环境:在Linux mint下,前几天还用得很好的的eclipse,今天开机不知为什么这样. Linux 下报错:A Java RunTime Environment (JRE) or Jav ...
- 读完了简明Python教程(a bite of Python)
因为学过C/C++,简明教程里很多共通的地方一看就明白. 明天做书最后的练习. <--! 代码占位 -->