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:
and here's the result with Windows XP theme:
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
:
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.
After exhausting research, I found it out. The thing is that when you call
within custom
ListView
class, it prevents visual styles from affecting the appearence of theListView
control but not theListView
header control (SysHeader32
window), which is child window ofListView
. So when calling theSetWindowTheme
function, we need to provide the handle of the header window instead of the handle of the ListView:Here's how to make the ListView header have the height you want:
C# - Listview colum header height (Windows Form)
What about disable visual styles ?
with this code you could disable style for one control (just use ListViewConstrol instead of ListView):
Looks like this is a known bug for which there is no easy workaround. According to the answer there:
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
.As Botz3000 mentioned in his answer that its a well known problem with
ListView
in Windows XP. Another workaround is to registerListView.DrawColumnHeader
event and reset the header font in it. You must setListView.OwnerDraw
property totrue
. MSDN code is as follows;In this case the header font will always be
"Helvetica", 10, FontStyle.Bold
and will not be effected by listview font. Check MSDN for further details.