更改的Winform的ListView头的背景颜色 [英] Change the background color of Winform ListView headers

查看:1235
本文介绍了更改的Winform的ListView头的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何改变ListView的页眉的背景颜色?

How can you change the background color of the Headers of a ListView?

推荐答案

您可以通过设置OwnerDraw属性列表视图,以真正做到这一点。

You can do this by setting the OwnerDraw property for the list view to true.

这则您可以为ListView的平局的事件过程。

This then allows you to provide event handlers for the listview's draw events.

有上 MSDN <详细示例/ A>

There is a detailed example on MSDN

下面是一些例子code将头颜色设置为红色:

Below is some example code to set the header colour to red:

    private void listView1_DrawColumnHeader(object sender,
                                            DrawListViewColumnHeaderEventArgs e)
    {
        e.Graphics.FillRectangle(Brushes.Red, e.Bounds);
        e.DrawText();
    }

我认为(但很高兴被证明是错误的),与的OwnerDraw设为true,则需要同时提供有默认的实现其它平局事件处理程序,如下所示:

I think (but am happy to be proved wrong) that with OwnerDraw set to true, you will need to also provide handlers for the other draw events that have default implementations as shown below:

    private void listView1_DrawItem(object sender,
                                    DrawListViewItemEventArgs e)
    {
        e.DrawDefault = true;
    }

我肯定没有设法使列表视图绘制的项目没有这一点。

I certainly haven't managed to make the listview draw the items without that.

这篇关于更改的Winform的ListView头的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆