我知道我可以将 OwnerDraw
属性更改为 true
,然后处理 DrawColumnHeader
事件,但如果我这样做,我有处理绘制标题的所有内容。
有没有我只是改变前景色而其他一切都使用默认值绘制的?
最佳答案
这个怎么样:
新建一个WinForm项目,拖一个ListView控件到窗体上,在Properties面板中设置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();
}
}
}
关于c# - 如何更改 ListView 标题的前景色? C# 窗体应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8818224/