在窗口的标题栏上绘制工具栏

时间:2022-07-16 15:53:17

How do I draw a toolbar on the titlebar of a C# winforms window in windows vista? I have a window where it works, except when the window is unminimized/unmaximized it increases in size by about 16x32px. If possible, please provide code examples.

如何在Windows Vista中的C#winforms窗口的标题栏上绘制工具栏?我有一个窗口可以工作,除非窗口未最小化/未最大化,它的大小增加大约16x32px。如果可能,请提供代码示例。

2 个解决方案

#1


The only way to effectively do it is to handle the WM_NCPAINT message when you override the WndProc method for the Form.

有效地执行此操作的唯一方法是在覆盖窗体的WndProc方法时处理WM_NCPAINT消息。

Passing to the base implementation of WndProc will cause the windows frame to be painted, but at that point, you would be responsibile for painting your toolbar elements on the title bar.

传递到WndProc的基本实现将导致绘制窗口框架,但此时,您将负责在标题栏上绘制工具栏元素。

You will also want to handle all the other WM_NC* messages as well, which will allow you to process button clicks and the like (which you will need to handle events for your painted controls).

您还需要处理所有其他WM_NC *消息,这将允许您处理按钮单击等(您需要处理绘制控件的事件)。

#2


I've been looking around for the same problem, because I wanted to code a ribbon bar with that big button in the upper left corner... The only good source I found was at CodeProject on this blog and this one and another one.

我一直在寻找相同的问题,因为我想用左上角的那个大按钮编写一个带状条形码...我发现的唯一好的来源是在这个博客上的CodeProject和另一个。

#1


The only way to effectively do it is to handle the WM_NCPAINT message when you override the WndProc method for the Form.

有效地执行此操作的唯一方法是在覆盖窗体的WndProc方法时处理WM_NCPAINT消息。

Passing to the base implementation of WndProc will cause the windows frame to be painted, but at that point, you would be responsibile for painting your toolbar elements on the title bar.

传递到WndProc的基本实现将导致绘制窗口框架,但此时,您将负责在标题栏上绘制工具栏元素。

You will also want to handle all the other WM_NC* messages as well, which will allow you to process button clicks and the like (which you will need to handle events for your painted controls).

您还需要处理所有其他WM_NC *消息,这将允许您处理按钮单击等(您需要处理绘制控件的事件)。

#2


I've been looking around for the same problem, because I wanted to code a ribbon bar with that big button in the upper left corner... The only good source I found was at CodeProject on this blog and this one and another one.

我一直在寻找相同的问题,因为我想用左上角的那个大按钮编写一个带状条形码...我发现的唯一好的来源是在这个博客上的CodeProject和另一个。