如何更改listview标题';什么是前景色?C#windows窗体应用程序

如何更改listview标题';什么是前景色?C#windows窗体应用程序,c#,winforms,visual-studio,listview,C#,Winforms,Visual Studio,Listview,我知道我可以将OwnerDraw属性更改为true,然后处理DrawColumnHeader事件,但如果我这样做,我必须处理绘制标题时的所有事情 是否我只需更改前景颜色,其他所有内容都以默认值绘制?这样如何: 创建一个新的WinForm项目,将一个ListView控件拖到表单上,在属性窗格中设置OwnerDraw=true,View=Details,然后处理DrawColumnHeader事件 namespace WindowsFormsApplication1 { public par

我知道我可以将
OwnerDraw
属性更改为
true
,然后处理
DrawColumnHeader
事件,但如果我这样做,我必须处理绘制标题时的所有事情

是否我只需更改前景颜色,其他所有内容都以默认值绘制?

这样如何:

创建一个新的WinForm项目,将一个ListView控件拖到表单上,在属性窗格中设置OwnerDraw=trueView=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();
        }
    }
}

否,这些标题是根据用户选择的视觉样式主题绘制的。在更高版本的Windows上使用渐变填充,它不仅仅是一种颜色。一定要问问自己,覆盖用户的偏好是否真的是你应该做的事情。是的,使用OwnerDraw强制您的偏好。