更改ListView的背景选择颜色?

Joe*_*ani 6 c# listview colors selection winforms

如何更改ListView上的选择颜色?默认情况下,当用户选择项目时,它显示蓝色背景.我想将其改为深灰色或其他东西......感谢您的帮助!

Zac*_*son 7

如果你想要你ListView拥有Windows资源管理器的风格ListView(包括在Win7/Vista中具有圆形边缘的漂亮外观),你可以使用一点P/Invoke来实现:

[DllImport("uxtheme.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
internal static extern int SetWindowTheme(IntPtr hWnd, string appName, string partList);

// You can subclass ListView and override this method
protected override void OnHandleCreated(EventArgs e)
{
    base.OnHandleCreated(e);
    SetWindowTheme(this.Handle, "explorer", null);
}
Run Code Online (Sandbox Code Playgroud)


Gra*_*ian 1

ObjectListView ——WinForm ListView 的包装器——具有可让您控制所选行的背景和前景色的属性。它使用了 Obalix 建议的技术,但它已经为您完成了艰苦的工作。

因此,只需付出一点努力,您就可以生成如下内容:

替代文本
(来源:codeproject.com

“Feel Good Inc”行显示自定义前景和背景以供选择。

  • `ObjectListView` 不是 `ListView` 的直接替代品。要使用它,很可能需要对现有代码进行一些重构。 (2认同)