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.
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
.
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With