.net WinForms 应用程序中的自定义标题栏/镶边
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42460/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Custom titlebars/chrome in a WinForms app
提问by OwenP
I'm almost certain I know the answer to this question, but I'm hoping there's something I've overlooked.
我几乎可以肯定我知道这个问题的答案,但我希望我忽略了一些东西。
Certain applications seem to have the Vista Aero look and feel to their caption bars and buttons even when running on Windows XP. (Google Chrome and Windows Live Photo Gallery come to mind as examples.) I know that one way to accomplish this from WinForms would be to create a borderless form and draw the caption bar/buttons yourself, then overriding WndProcto make sure moving, resizing, and button clicks do what they're supposed to do (I'm not clear on the specifics but could probably pull it off given a day to read documentation.) I'm curious if there's a different, easier way that I'm overlooking. Perhaps some API calls or window styles I've overlooked?
即使在 Windows XP 上运行时,某些应用程序的标题栏和按钮似乎也具有 Vista Aero 的外观和感觉。(谷歌浏览器和 Windows Live 照片库作为例子浮现在脑海中。)我知道从 WinForms 实现这一点的一种方法是创建一个无边框表单并自己绘制标题栏/按钮,然后覆盖WndProc以确保移动、调整大小、和按钮点击做他们应该做的事情(我不清楚具体细节,但可能会在一天阅读文档的情况下完成。)我很好奇是否有一种不同的、更简单的方法可以让我忽略. 也许我忽略了一些 API 调用或窗口样式?
I believe Google has answered it for me by using the roll-your-own-window approach with Chrome. I will leave the question open for another day in case someone has new information, but I believe I have answered the question myself.
我相信谷歌已经通过在 Chrome 中使用滚动你自己的窗口方法为我回答了这个问题。如果有人有新信息,我会将问题留待一天,但我相信我自己已经回答了这个问题。
采纳答案by Chris Pietschmann
Here's an article with full code sample on how to use your own custom "chrome" for an application:
这是一篇关于如何为应用程序使用您自己的自定义“chrome”的完整代码示例文章:
http://geekswithblogs.net/kobush/articles/CustomBorderForms3.aspx
http://geekswithblogs.net/kobush/articles/CustomBorderForms3.aspx
This looks like some really good stuff. There are a total of 3 articles in it's series, and it runs great, and on Vista too!
这看起来像一些非常好的东西。它的系列共有 3 篇文章,运行良好,在 Vista 上也运行良好!
回答by OwenP
Google Chrome is notusing the Vista SDK to achieve this on XP. If you peek into src\chrome\browser\views\framethere are several files to define the browser frame depending on the capabilities of the system. On XP, it looks like OpaqueFrameis used; line 19 has this to say:
谷歌浏览器没有使用 Vista SDK 在 XP 上实现这一点。如果您查看src\chrome\browser\views\frame有几个文件可以根据系统的功能定义浏览器框架。在 XP 上,它看起来像OpaqueFrame被使用了;第 19 行是这样说的:
// OpaqueFrame
//
// OpaqueFrame is a CustomFrameWindow subclass that in conjunction with
// OpaqueNonClientView provides the window frame on Windows XP and on Windows
// Vista when DWM desktop compositing is disabled. The window title and
// borders are provided with bitmaps.
It looks like it's using the resources in src\chrome\app\themeto draw the frame buttons.
看起来它正在使用资源src\chrome\app\theme来绘制框架按钮。
So it looks like my hopes that there's some kind of cheap way to enable Vista theming on XP are dashed. The only way to do it is to manually draw the non-client area of your window. I believe something like thisis probably the right track, since it lets Windows handle the non-client stuff like moving and resizing the window.
所以看起来我希望有某种廉价的方式在 XP 上启用 Vista 主题化的希望破灭了。唯一的方法是手动绘制窗口的非客户区。我相信这样的事情可能是正确的,因为它让 Windows 处理非客户端的事情,比如移动和调整窗口大小。
Unless someone can find a method to magically enable the Vista theming on XP, this is the answer to the question but I obviously cannot mark my own post as the answer.
除非有人能找到一种方法在 XP 上神奇地启用 Vista 主题,否则这就是问题的答案,但我显然不能将我自己的帖子标记为答案。
回答by Judah Gabriel Himango
Owen, I'm using Chrome on XP and I don't see "Vista Aero" glass theme on the Chrome window. I see it as solid blue.
Owen,我在 XP 上使用 Chrome,但在 Chrome 窗口上看不到“Vista Aero”玻璃主题。我认为它是纯蓝色的。
If it's custom theming of controls and windows title bars you want, that can be accomplished. There's an excellent, free UI toolkit for WinForms that does exactly that: KryptonToolkit
如果它是您想要的控件和窗口标题栏的自定义主题,则可以实现。有一个出色的、免费的 WinForms 用户界面工具包可以做到这一点:KryptonToolkit
回答by FlySwat
Google Chrome uses the Windows Vista SDK to get the glass look on XP. You can download it here:
Google Chrome 使用 Windows Vista SDK 在 XP 上获得玻璃外观。您可以在这里下载:
Using this, you need to enabled delay loading of the following DLL's to get the Glass Effect in XP:
使用它,您需要启用以下 DLL 的延迟加载才能在 XP 中获得玻璃效果:
- uxtheme.dll
- dwmapi.dl
- 文件主题.dll
- dwmapi.dl

