.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重绘的更多相关文章

  1. uCGUI窗口重绘代码分析

    一.概述 µC/GUI的窗口重绘是学习者理解窗口工作原理和应用窗口操作的重点.µC/GUI的窗口重绘引入了回调机制,回调机制可以实现图形系统调用用户的代码,由于图形系统使用了剪切算法,使得屏幕重绘的效 ...

  2. 深入Windows窗体原理及控件重绘技巧

    之前有学MFC的同学告诉我觉得Windows的控件重绘难以理解,就算重绘成功了还是有些地方不明白,我觉得可能很多人都有这样的问题,在这里我从Windows窗体的最基本原理来讲解,如果你有类似的疑惑希望 ...

  3. VC++中关于控件重绘函数/消息 OnPaint,OnDraw,OnDrawItem,DrawItem的区别

    而OnPaint()是CWnd的类成员,同时负责响应WM_PAINT消息. OnDraw()是CVIEW的成员函数,并且没有响应消息的功能.这就是为什么你用VC成的程序代码时,在视图类只有OnDraw ...

  4. 使用重绘项美化WinForm中的控件

    如果你觉得项目中的ComboBox.ListBox或其它的Winforms控件不能满足你的显示要求,包括窗体在内很多控件都支持重绘修改显示样式.下面的示例完成对ComBox数据项的重绘,希望能起到抛砖 ...

  5. 关于DOM的操作以及性能优化问题-重绘重排

     写在前面: 大家都知道DOM的操作很昂贵. 然后贵在什么地方呢? 一.访问DOM元素 二.修改DOM引起的重绘重排 一.访问DOM 像书上的比喻:把DOM和JavaScript(这里指ECMScri ...

  6. 关于repaint(重绘)和reflow( 回流)

    repaint就是重绘,reflow就是回流.repaint主要是针对某一个DOM元素进行的重绘,reflow则是回流,针对整个页面的重排 严重性: 在性能优先的前提下,性能消耗 reflow大于re ...

  7. MFC 滑动条的重绘

    MFC自带的滑动条的样子是这样的. 比较难看,所以需要重绘下,重绘后的样子是这样的. 代码如下: CustomSliderCtr.h #pragma once // CCustomSliderCtr ...

  8. WinForm中重绘TabControl选项卡标题

    最近开发WinForm频繁使用了TabControl控件,这个控件的选项卡没有BackgroundImage这个属性,那么如何为其各个选项卡添加背景图片呢?(这里说的是每个TabPage的头部,也就是 ...

  9. 回流(reflow)与重绘(repaint)

    最近项目排期不紧,于是看了一下之前看了好久也没看明白的chrome调试工具的timeline.但是很遗憾,虽然大概懂了每一项是做什么的,但是用起来并不能得心应手.所以今天的重点不是timeline,而 ...

随机推荐

  1. Vue.js 2.0 和 React、Augular

    Vue.js 2.0 和 React.Augular 引言 这个页面无疑是最难编写的,但也是非常重要的.或许你遇到了一些问题并且先前用其他的框架解决了.来这里的目的是看看Vue是否有更好的解决方案.那 ...

  2. 在ios开发中有多少常用的加密解密方式(备用)

    最常用的是MD5和base64编码,还有DES 3DES AES加密 ios怎么实现RAS加密解密 最近几天折腾了一下如何在iOS上使用RSA来加密.iOS上并没有直接的RSA加密API.但是iOS提 ...

  3. LightOj_1287 Where to Run

    题目链接 题意: 有n个街口和m条街道, 你后边跟着警察,你需要进行大逃亡(又是大爱的抢银行啊),在每个街口你都有≥1个选择, 1)停留在原地5分钟. 2)如果这个街口可以到xi这个街口, 并且, 通 ...

  4. 不同框架实现的WebService的服务端获取HttpServletRequest的方法

    一. 基于xfire实现的WebService HttpServletRequest request = XFireServletController.getRequest(); 二. 基于axis实 ...

  5. 李洪强漫谈iOS开发[C语言-031]-逻辑短路

  6. DHTMLX 前端框架 建立你的一个应用程序教程(四)--添加一个工具条toolbar

    工具条例子 样本如下: 这里我们使用的是dhtmlxToolbar 组件. 添加工具栏到布局中: 1.使用attachToolbar() 方法初始化页面 添加代码到index.html中 dhtmlx ...

  7. app:layout_scrollFlags不起作用

    http://stackoverflow.com/questions/31722798/enteralwayscollapsed-does-not-bring-back-the-toolbar-whe ...

  8. insert into select 堵塞update

    mysql[192.168.5.15] blocking_thread[2286333] blocking_query[insert into temp_zhuyou_mktact_1(hotel_g ...

  9. sort merge join导致temp被爆菊

    SQL_ID cqsz37256v36j, child number 1 ------------------------------------- INSERT /*+append*/ INTO T ...

  10. 解决MySQL服务启动时报1067错误

    工具/原料 MySQL_5.6.24_win32 方法/步骤 当我们安装完Mysql时,如果在服务当中(可以在“运行”-->"service.msc"打开并查看)无法看到My ...