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,而 ...
随机推荐
- python类库26[web2py之基本概念]
一 web2py的应用的执行环境Models,Controllers和views所在的执行环境中,以下对象已经被默认地导入: Global Objects: request,response,ses ...
- 【资料目录收藏】.NET开发必看资料53个 经典源码77个
简单描述:为大家整理了下载中心.net资料,都是比较热的,好评率比较高的,做了一个可收藏的下载目录,希望大家喜欢~ 基于.net构架的留言板项目大全源码 http://down.51cto.com/z ...
- 7 -- Spring的基本用法 -- 8...
7.8 深入理解容器中的Bean 7.8.1 抽象Bean与子Bean 把多个<bean.../>配置中相同的信息提取出来,集中成配置模版------这个配置模版并不是真正的Bean,因此 ...
- [BZOJ 2738] 矩阵乘法 【分块】
题目链接:BZOJ - 2738 题目分析 题目名称 “矩阵乘法” 与题目内容没有任何关系..就像VFK的 A+B Problem 一样.. 题目大意是给定一个矩阵,有许多询问,每次询问一个子矩阵中的 ...
- Android Environment 判断sd卡是否挂载 获取sd卡目录
在将一个文件存储到sd卡上面的时候,一般需要判断sd是否已经挂载才进行操作. 那么如何判断sd卡已经挂载呢? 我们可以使用Android的Environment类,具体使用如下: if(Environ ...
- [转贴]JAVA :RESTLET开发实例(一)基于JAX-RS的REST服务
RESTLET介绍 Restlet项目为“建立REST概念与Java类之间的映射”提供了一个轻量级而全面的框架.它可用于实现任何种类的REST式系统,而不仅仅是REST式Web服务. Restlet项 ...
- SPRING IN ACTION 第4版笔记-第三章ADVANCING WIRING-005-Bean的作用域@Scope、ProxyMode
一. Spring的bean默认是单例的 But sometimes you may find yourself working with a mutable class that does main ...
- ASP.NET MVC 下 引用阿里巴巴和IconFont字体路径404问题
参考:http://stackoverflow.com/questions/28169365/font-wont-get-found-on-server-for-firefox# http://blo ...
- 【CF】174 Div.1 B Cow Program
思路是树形DP+状态压缩.其实仅有2个状态,奇数次来到x或者偶数次来到x.(因为对x的更新不同).同时开辟visit数组,解决环.注意,一旦遇到环结果就是-1.DP数组存放第奇数/偶数次来到x时,对y ...
- hadoop2.2编程:DFS API 操作
1. Reading data from a hadoop URL 说明:想要让java从hadoop的dfs里读取数据,则java 必须能够识别hadoop hdfs URL schema, 因此我 ...