Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7802009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:07:41+00:00 2026-06-02T01:07:41+00:00

I’ve created new Windows Forms Application (C#) with one simple form containing ListView. Then

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:07:43+00:00Added an answer on June 2, 2026 at 1:07 am

    After exhausting research, I found it out. The thing is that when you call

    SetWindowTheme(this.Handle, "", "");
    

    within custom ListView class, it prevents visual styles from affecting the appearence of the ListView control but not the ListView header control (SysHeader32 window), which is child window of ListView. So when calling the SetWindowTheme function, we need to provide the handle of the header window instead of the handle of the ListView:

    [DllImportAttribute("uxtheme.dll")]
    private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);
    
    [DllImport("user32")]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr i);
    
    // Callback method to be used when enumerating windows:
    private static bool EnumWindow(IntPtr handle, IntPtr pointer)
    {
        GCHandle gch = GCHandle.FromIntPtr(pointer);
        List<IntPtr> list = gch.Target as List<IntPtr>;
        if (list == null)
            throw new InvalidCastException("GCHandle Target could not be cast as List<IntPtr>");
        list.Add(handle);
        return true;
    }
    
    // delegate for the EnumChildWindows method:
    private delegate bool EnumWindowProc(IntPtr hWnd, IntPtr parameter);
    
    // get first child:
    private static void DisableVisualStylesForFirstChild(IntPtr parent)
    {
        List<IntPtr> children = new List<IntPtr>();
        GCHandle listHandle = GCHandle.Alloc(children);
        try
        {
            EnumWindowProc childProc = new EnumWindowProc(EnumWindow);
            EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle));
            if (children.Count > 0)
                SetWindowTheme(children[0], "", "");
        }
        finally
        {
            if (listHandle.IsAllocated)
                listHandle.Free();
        }
    }
    
    protected override void OnHandleCreated(EventArgs e)
    {
        DisableVisualStylesForFirstChild(this.Handle);
        base.OnHandleCreated(e);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.