更改窗口的最小化、关闭和最大化图标
简单的问题。如何更改关闭、最小化、最大化按钮的图标。我可以在 Winforms 和 WPF 中执行此操作吗?
Simple question. How can I change the icons of the close, minimize, maximize buttons. Can I do this in Winforms and WPF?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这些图标、标题和窗口边框都是在处理 WM_NCPAINT 消息时绘制的。因此,您接管绘图的方法是处理此消息。
但是您无权访问有关图标的状态信息(即您应该在按下状态下绘制哪个按钮,因为用户当前正在单击它。)。您甚至不知道鼠标处理代码认为这些图标到底在哪里。
因此,要接管非客户端绘制,您还需要接管非客户端鼠标处理,整个问题就会像滚雪球一样越滚越大,直到您编写了数千行代码而您的窗口仍然没有'当用户尝试拖动它时,它的行为会非常正确,等等。
这是在非托管代码中,在托管代码(C#/.Net)中,这甚至更难,因为您还必须进行互操作才能访问您需要的一些 API使用。
所以答案是:是的,这是可能的,但是在WinForms和WPF中比在C++中更难,那些尝试过的人现在都秃了。
These Icons, the caption, and the border on your window are all drawn while processing the WM_NCPAINT message. So, the way you take over drawing this is by handling this message.
But you don't have access to the state information about the icons (i.e. which button you should draw in it's pressed state because the user is currently clicking on it.). You dont even know where exactly the mouse handling code thinks these icons are.
So to take over non-client paint, you also need to take over non-client mouse handling, and the whole problem just snowballs until you've written thousands of lines of code and your window still doesn't behave quite right when the user tries to drag it, etc.
And that's in unmanaged code, in managed code (C#/.Net) this is even harder because you also have to do interop to get to some of the APIs you need to use.
So the answer is: Yes its possible, but its harder in WinForms and WPF than it is in C++, and those that have attempted it are all bald now.
真正的答案是你不应该这样做。用户希望所有应用程序都能正常工作并且外观相同。让他们尝试找出你使用的新图标意味着最小化可能会让他们不高兴。
The real answer is that you shouldn't do this. Users expect all applications to work and look the same. Making them try an figure out what spiffy new icon you use means minimize is likely to make them unhappy.
这样做并不困难,但工作量很大 - 您必须基本上更换窗口框架并自己处理所有事情,默认窗口框架中有很多功能您必须重写 - 您还必须编写不同的代码适用于启用 Aero 的 Vista/7。
在 WPF 中,您可以使用 http://blogs.msdn.com/wpfsdk/archive/2008/09/08/custom-window-chrome-in-wpf.aspx
在 WinForms 中,您使用相同的基本技术,但我不这样做知道一个总结了所有详细信息的页面,如上面的链接。
Doing this isn't difficult but it is a lot of work - you have to basically replace the window frame and handle everything yourself, there is a lot of functionality in the default window frame you have to rewrite - you also have to write different code for Vista/7 with Aero enabled.
In WPF you use the various techniques in http://blogs.msdn.com/wpfsdk/archive/2008/09/08/custom-window-chrome-in-wpf.aspx
In WinForms you use the same basic techniques but I don't know of a page that summarizes all the details like the link above.
在 wpf 中,您可以为窗口设置 WindowStyle="None",然后为其设置自定义标题栏,并带有最小化、最大化和关闭按钮。我之前已经这样做过。您需要执行一些事件处理来执行最小化、最大化、关闭、拖动等。
In wpf, you can set
WindowStyle="None"
for your Window and then set a custom TitleBar for that, with minimize, maximize and close button. I have done this earlier. You need to do some event handling to perform minimize, maximize, close, drag etc.是的,您必须创建自己的窗口样式。参考FluidKit,例如GlassWindows。
Yes, you have to create your own window style. Refer to FluidKit, GlassWindows for example.
如果您想控制这些按钮的外观,则必须创建自己的按钮。这是使用 Windows 功能编写 Windows 应用程序的价值之一(它们具有标准的外观和感觉)。
If you want to control the look of those buttons, you'll have to create your own. This is one value of using Windows features to write windows applications (they come with a standard look and feel).