在不禁用主题的情况下设置 Windows 区域 [英] Setting a windows region without disabling theming
问题描述
有谁知道如何分配窗口区域(WinForms 中的SetWindowRgn
或 Control.Region
)而不杀死非客户区的主题?
例如,运行以下命令会生成一个 Windows 2000 风格的无主题标题栏、边框等:
var form = new Form { Width=500, Height=500, BackColor = Color.Azure };form.Text = "但是很柔和,从那扇窗户射进来的光是什么?";var region = new Region(new Rectangle (Point.Empty, form.Size));region.Exclude (新矩形 (100, 100, 300, 300));form.Region = 区域;form.ShowDialog();
我猜这与
Does anyone know how to assign a window region (SetWindowRgn
or Control.Region
in WinForms) without killing the theming in the non-client area?
For example, running the following generates a Windows 2000-style unthemed title bar, border, etc:
var form = new Form { Width=500, Height=500, BackColor = Color.Azure };
form.Text = "But soft, what light through yonder window breaks?";
var region = new Region (new Rectangle (Point.Empty, form.Size));
region.Exclude (new Rectangle (100, 100, 300, 300));
form.Region = region;
form.ShowDialog();
I'm guessing it's to do with this MSDN article which says:
As long as a window has a non-NULL region applied to it (SetWindowRgn), the UxTheme Manager assumes that this is a specialized window and the window will not use visual styles.
...hence UxThemes assumes it's a specialized window. Is there a way to tell the UxTheme Manager explicitly to theme a window?
The answer to your question is that you cannot.
But a workaround, to give you a transparent section in your form, would be to add the WS_EX_LAYERED
extended window style to your form. Then you can tell the Window Manager that you want to use a chroma-color key to make part of your form transparent:
SetLayeredWindowAttributes(
Form.Handle, // __in HWND hwnd,
RGB(0, 255, 0), //green is the color key __in COLORREF crKey,
255, //window is opaque otherwise __in BYTE bAlpha,
LWA_COLORKEY //use color-key (rather than per-pixel alpha) __in DWORD dwFlags
);
Then you can put your "transparent" area as lime green:
Which then at runtime will be transparent:
Update: When i use layered window to have full transparency mouse events do trickle through to what's underneath. Notice the "flag" icon highlight:
See also
- Window Overview -> Window Features -> Layered Windows
- SetLayeredWindowAttributes Function
- Extended Window Styles
- Layered Windows
这篇关于在不禁用主题的情况下设置 Windows 区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!