.NET ListView and Windows 7

Maybe something is missing for me, but ... The ListView control in Windows 7 displays a selection around the selected items, which looks like a three-dimensional blue translucent rectangle (I'm not talking about the selection rectangle, but about the rectangle around the actual selected items). It even shows a lighter rectangle when you hover over items.

However, when I use ListView in WinForms (even with double buffering), the selected items have a simple blue background (and no background image) that looks much less professional than, say, a list in Explorer.

Does anyone know which secret API function I must call to make the .NET ListView fit the rest of the OS?

For example, here is one of my applications written in C ++ using the standard ListView control in Windows 7: (pay attention to the selection and hover rectangle)

alt text

And here is the rewriting of this application in C # with WinForms: (pay attention to the rough highlighting and the lack of freezing)

alt text

+5
source share
3 answers

Well, I fully understood this, and it can help others who are concerned about this issue.

, , ListView ++ Builder "" Windows 7, VCL, , , ListView : Windows. , :

SetWindowTheme(Handle, 'explorer', nil);

SDK " , ".

, ListView WinForms:

[DllImport("uxtheme.dll", CharSet = CharSet.Unicode)]
public static extern int SetWindowTheme(IntPtr hWnd, String pszSubAppName, String pszSubIdList);


SetWindowTheme(myListView.Handle, "explorer", null);

... , , ! ListView, , , ! , Borland Inprise Embarcadero! -!

+12
Imports System.Runtime.InteropServices

Public Class Form1
    <DllImport("uxtheme", CharSet:=CharSet.Unicode)> _
    Public Shared Function SetWindowTheme(ByVal hWnd As IntPtr, ByVal textSubAppName As String, ByVal textSubIdList As String) As Integer
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SetWindowTheme(lst.Handle, "explorer", Nothing)
    End Sub
End Class

...

+1

edit: , :

 <DllImport("uxtheme.dll",
  BestFitMapping:=False,
  CharSet:=CharSet.Unicode,
  EntryPoint:="#136",
  CallingConvention:=CallingConvention.Winapi)>
  Private Shared Function SetWindowsTheme(ByVal handle As IntPtr, ByVal app As String, ByVal id As String) As Integer
        ' Leave function empty - DLLImport attribute forwards calls to the right function 
    End Function


Public Shared Sub MakeControlLookBeautiful(ByVal c As Windows.Forms.Control)
    SetWindowsTheme(c.Handle, "explorer", Nothing)
End Sub

:)

0

All Articles