gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 22:32:59 24 4
gpt4 key购买 nike

我正在创建一个简单的 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;
}

参见 msdn了解更多信息。

关于c# - 在 C# 中更改 ListView 列的字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8518317/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com