Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows theme affecting ListView header

I've created new Windows Forms Application (C#) with one simple form containing ListView. Then I have changed the View Property to Details and increased the size of the font used in this ListView and here's the result:

This is how it looks on Windows XP with Windows Classic theme:
enter image description here

and here's the result with Windows XP theme:
enter image description here

I can prevent the appearance of my application to be affected by Visual Styles either by removing Application.EnableVisualStyles() call or by changing the Application.VisualStyleState: enter image description here
Although this change makes the ListView to have the desired appearance, it also affects the appearance of other controls. I'd like my ListView to be the only control that is not affected by Visual Styles.

I've also found similar questions that try to deal with it:
Can you turn off visual styles/theming for just a single windows control?
How do I disable visual styles for just one control, and not its children?

Unfortunately, none of mentioned solutions works. It looks like the header itself would be made up of some controls that are affected by visual styles even when visual styles for ListView control are disabled.

Any C# solution that would prevent visual styles from affecting the appearance of the ListView header would be appreciated.

like image 797
LihO Avatar asked Apr 11 '12 09:04

LihO


2 Answers

Looks like this is a known bug for which there is no easy workaround. According to the answer there:

After doing a lot of research with this issue, we find that this is a windows OS bug, which the ComCtl6.0 header control forgets to apply the font information to the drawing DC.

However you could draw the column header yourself. See this article on MSDN for details on how to do it and also look at listView1_DrawColumnHeader.

like image 67
Botz3000 Avatar answered Sep 23 '22 04:09

Botz3000


What about disable visual styles ?

with this code you could disable style for one control (just use ListViewConstrol instead of ListView):

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

public class ListViewControl : ListView {
  [DllImportAttribute("uxtheme.dll")]
  private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);

  protected override void OnHandleCreated(EventArgs e) {
    SetWindowTheme(this.Handle, "", "");
    base.OnHandleCreated(e);
  }
}
like image 45
Kamil Lach Avatar answered Sep 24 '22 04:09

Kamil Lach