Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After exhausting research, I found it out. The thing is that when you call</p> <pre><code>SetWindowTheme(this.Handle, "", ""); </code></pre> <p>within custom <code>ListView</code> class, it prevents visual styles from affecting the appearence of the <code>ListView</code> control but not the <code>ListView</code> header control (<code>SysHeader32</code> window), which is child window of <code>ListView</code>. <strong>So when calling the <code>SetWindowTheme</code> function, we need to provide the handle of the header window instead of the handle of the ListView:</strong></p> <pre><code>[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&lt;IntPtr&gt; list = gch.Target as List&lt;IntPtr&gt;; if (list == null) throw new InvalidCastException("GCHandle Target could not be cast as List&lt;IntPtr&gt;"); 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&lt;IntPtr&gt; children = new List&lt;IntPtr&gt;(); GCHandle listHandle = GCHandle.Alloc(children); try { EnumWindowProc childProc = new EnumWindowProc(EnumWindow); EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle)); if (children.Count &gt; 0) SetWindowTheme(children[0], "", ""); } finally { if (listHandle.IsAllocated) listHandle.Free(); } } protected override void OnHandleCreated(EventArgs e) { DisableVisualStylesForFirstChild(this.Handle); base.OnHandleCreated(e); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload