Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更改C中ListView列的字体大小#_C#_Winforms_Listview_Fonts - Fatal编程技术网

C# 更改C中ListView列的字体大小#

C# 更改C中ListView列的字体大小#,c#,winforms,listview,fonts,C#,Winforms,Listview,Fonts,我正在创建一个简单的GUI,其中包含一个用于触摸屏显示器的listView。因此,我要求文本要大,所以它很容易阅读和选择。我可以更改listView的Font属性以增加其大小,尽管这也会按比例增加列标题的字体大小(使字母对于空格来说太大) 是否有方法仅更改listView项目的字体大小和/或更改列的文本空间大小以适应较大的字母 我想我可以使用ListBox.DrawColumnHeader事件来进行此操作,但我无法准确地找出如何将其组合在一起 提前感谢这将有助于: // Draws column

我正在创建一个简单的GUI,其中包含一个用于触摸屏显示器的listView。因此,我要求文本要大,所以它很容易阅读和选择。我可以更改listView的Font属性以增加其大小,尽管这也会按比例增加列标题的字体大小(使字母对于空格来说太大)

是否有方法仅更改listView项目的字体大小和/或更改列的文本空间大小以适应较大的字母

我想我可以使用ListBox.DrawColumnHeader事件来进行此操作,但我无法准确地找出如何将其组合在一起

提前感谢

这将有助于:

// 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;
}

有关更多信息,请参阅。

我在这里找到了解决方案:它涉及使用OwnerDraw属性来设计表单。这意味着要详细说明它的各个方面。但是,在上面的链接中使用相同的代码可以得到结构,然后只需填写空格(例如行颜色/字体等)。要修改ListView列的字体大小,请查看listView1\u DrawColumnHeader事件。代码被很好地注释和解释,以确保理解好运!这是怎么做的,谢谢!我找到了与所有感兴趣的人的完整示例代码相同的链接,如下所示: