更改字体大小在C#中的ListView列 [英] Changing Font Size for ListView Column in C#

查看:3400
本文介绍了更改字体大小在C#中的ListView列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个简单的GUI,含这将是带触摸屏的显示器使用一个ListView。因此,我要求要大的文本,所以它很容易读取和选择。我可以改变的字体我的ListView的属性来增加它的大小,虽然这也增加比例列标题字体大小(使字母太大的空间)。

I am creating a simple GUI, containing a listView which will be for use with a touch screen monitor. Therefore I require the text to be large, so it is easily readable and selectable. I can change the Font property of my listView to increase its size, although this also increases the column header font size in proportion (making the letters too big for the space).

有没有改变只是ListView的项目和/或改变列的文本空间大小的一种手段的字体大小,以满足更大的字母的方法?

Is there a method to change just the font size of the listView items and/or a means of changing the size of the text space of the column to cater for bigger letters?

我想我可以使用 ListBox.DrawColumnHeader 事件这一点,但我无法弄清楚究竟是如何拼凑在一起!

I think I can use the ListBox.DrawColumnHeader event for this but I cannot figure out exactly how to piece it together!

在此先感谢

推荐答案

这可以帮助:

// Draws column headers.
private void listView1_DrawColumnHeader(object sender,
    DrawListViewColumnHeaderEventArgs e)
{
    using (StringFormat sf = new StringFormat())
    {
        // Store the column text alignment, letting it default
        // to Left if it has not been set to Center or Right.
        switch (e.Header.TextAlign)
        {
            case HorizontalAlignment.Center:
                sf.Alignment = StringAlignment.Center;
                break;
            case HorizontalAlignment.Right:
                sf.Alignment = StringAlignment.Far;
                break;
        }

        // Draw the standard header background.
        e.DrawBackground();

        // Draw the header text.
        using (Font headerFont =
                    new Font("Helvetica", 10, FontStyle.Bold)) //Font size!!!!
        {
            e.Graphics.DrawString(e.Header.Text, headerFont,
                Brushes.Black, e.Bounds, sf);
        }
    }
    return;
}

请参阅 MSDN 了解信息。

这篇关于更改字体大小在C#中的ListView列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆