.NET ListView和Windows 7的 [英] .NET ListView and Windows 7
问题描述
也许我失去了一些东西,但是...
在Windows 7中显示ListView控件围绕所选项目的一大亮点,看起来像一个3D的蓝色透明的矩形(我不是在谈论选择矩形,但各地实际所选项目的矩形)。它甚至可以显示一个打火机矩形上空盘旋项目时。
Maybe I'm missing something, but... The ListView control in Windows 7 displays a highlight around selected items that looks like a 3D blue translucent rectangle (I'm not talking about the selection rectangle, but the rectangle around the actual selected items). It even shows a lighter rectangle when hovering over items.
然而,当我使用的WinForms(即使双缓冲)ListView控件,选定的项目只是一个普通的蓝色背景(没有悬停背景),它看上去很专业更比说,名单中的资源管理器。
However, when I use the ListView in WinForms (even when double-buffered), the selected items just have a plain blue background (and no hover background) which looks much less professional than, say, the list in Explorer.
有谁知道我应该叫什么秘密API功能,使排队的.NET ListView控件的外观与操作系统的其他部分?
Does anyone know what secret API function I should call to make the .NET ListView look in line with the rest of the OS?
例如,这里是用C ++编写我的应用程序之一,使用Windows 7标准的ListView控件:(注意亮点和悬停矩形)
For example, here is one of my applications written in C++, using a standard ListView control in Windows 7: (notice the highlight and hover rectangle)
这是在C#该应用程序使用的WinForms的改写:
And here is a rewrite of that application in C# with WinForms: (notice the crude highlight and no hover)
推荐答案
OK,我完全理解了它,这可能会帮助其他人谁可能受到此问题困扰。
OK, I totally figured it out, and this may help others who are bothered by this issue.
我开始注意到,在C ++ Builder中的ListView控件看起来正确在Windows 7下,所以我看着在源$ C $ C为VCL,看看他们在做什么样的魔力,使的ListView看起来像在Windows资源管理器的列表控件。我偶然在code的一条线,看起来有希望的:
I began by noticing that the ListView control in C++Builder looks "correct" under Windows 7, so I looked in the source code for the VCL to see what kind of magic they're doing to make the ListView look like the list control in Windows Explorer. I stumbled on one line of code that looked promising:
SetWindowTheme(Handle, 'explorer', nil);
从SDK文档,此功能使得一个窗口使用一组不同的比同级车通常使用视觉样式信息。
From the SDK documentation, this function "Causes a window to use a different set of visual style information than its class normally uses."
所以,我试着在我的WinForms ListView控件调用这个函数:
So, I tried invoking this function on my WinForms ListView control:
[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公司!你真的是好东西!
...and, by god, it worked! The ListView finally looks like it belongs with the rest of the OS! Thanks, Borland Inprise Embarcadero! You really are good for something!
这篇关于.NET ListView和Windows 7的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!