c# - 如何更改 ListView 标题的前景色? C# 窗体应用程序

标签 c# winforms visual-studio listview

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

有没有我只是改变前景色而其他一切都使用默认值绘制的?

最佳答案

这个怎么样:

新建一个WinForm项目,拖一个ListView控件到窗体上,在Properties面板中设置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();
        }
    }
}

关于c# - 如何更改 ListView 标题的前景色? C# 窗体应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8818224/

相关文章:

c# - 如何使用 EPPlus 在工作表上设置页面布局中断

c# - 使用 LINQ 将 XML 数据插入现有 XML

c# - 是否有 OO 模型来生成 SQL?

java - Java 是否可以像 C# 一样进行表单设计?

c# - 取消后台任务

c++ - 使用 BYTE 类型的变量是否可移植?

c# - 如何将List <Object>转换为继承类的数组?

c# - 共享文件夹API

visual-studio - Sharepoint 工作流程开发(2 部分问题)

c++ - 为什么我不能在 MinGW 中链接 64 位 .lib 文件?