如何更改列表视图标题';s的前景?C#窗体应用程序
本文关键字:应用程序 窗体 列表 何更改 视图 标题 | 更新日期: 2023-09-27 18:19:55
我知道我可以将OwnerDraw
属性更改为true
,然后处理DrawColumnHeader
事件,但如果我这样做,我必须处理绘制标头时的所有问题。
我只是更改了前景色,其他的都是用默认值绘制的吗?
这个怎么样:
创建一个新的WinForm项目,将ListView控件拖到窗体上,在"属性"窗格中设置OwnerDraw=true,View=Details然后处理DrawColumnHeader事件。
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.SetLastColumnWidth();
this.theListView.Layout += delegate
{
this.SetLastColumnWidth();
};
}
private void SetLastColumnWidth()
{
// Force the last ListView column width to occupy all the
// available space.
this.theListView.Columns[ this.theListView.Columns.Count - 1 ].Width = -2;
}
private void listView1_DrawColumnHeader( object sender, DrawListViewColumnHeaderEventArgs e )
{
// Fill header background with solid yello color.
e.Graphics.FillRectangle( Brushes.Yellow, e.Bounds );
// Let ListView draw everything else.
e.DrawText();
}
}
}