没有边框的大型应用程序(FormBorderStyle = Sizable)

时间:2013-12-09 20:09:24

标签: vb.net dwm

如何隐藏默认窗口(窗体)边框(我想使用我的),但仍然可以使用捕捉和表格阴影?

在(桌面)Win 8上开发,认为它是DWM API函数或类似的东西。

PS:我是DWM的新手。

1 个答案:

答案 0 :(得分:0)

好的,我终于找到了解决问题的方法。

最初我使用的是WinForms,但多年来我转而使用WPF。

WPF得到了一个名为WindowChrome的东西,它是Window框架/持有者,它保存着Window内容和窗口。每次有新的Windows迭代时都会更改。

我发现有一个函数可以很容易地更改Window的WindowChrome属性。

我创建了自己的函数,我可以在其中传递新chrome的属性:

/// <summary>
/// Changes the WindowChrome of selected Window (wnd) &amp; adjust its properties
/// </summary>
/// <param name="wnd">Window to affect</param>
/// <param name="glassThickness">Thickness of glass border (0 - no glass = no shadow, lower than 0 - whole window, higher than 0 - real border)</param>
/// <param name="resBorder">Thickness of resize border - where Windows natively supports resizing of the window</param>
/// <param name="topMove">Height of the window header/title - Windows native support for changing position of the window (from top), disables mouse events of controls underneath it</param>
/// <remarks></remarks>
public void NiceChrome(Window wnd, Thickness glassThickness, Thickness resBorder, int topMove)
{
    WindowStyle = WindowStyle.SingleBorderWindow;
    Shell.WindowChrome.SetWindowChrome(wnd, new Shell.WindowChrome
    {
        ResizeBorderThickness = resBorder,
        GlassFrameThickness = glassThickness,
        UseAeroCaptionButtons = false,
        CaptionHeight = topMove,
        CornerRadius = new CornerRadius(0),
        NonClientFrameEdges = Shell.NonClientFrameEdges.None
    });
}

如果有人想使用这个功能,我希望我的评论很容易理解。我还发现在glassThickness上使用厚度(-1)会使整个窗口下面有玻璃,而不会在窗口外部提供任何额外的空间/边框,但仍然保持投影效果。

另一个注意事项是,您必须在最大化时更改窗口的填充,因为Windows仍然希望切断不再存在的边框/玻璃。

PS:英语不是我的母语,如果语法中有任何问题,请在编辑时修复它。谢谢&amp;是的,我回答了近两年的问题(我的意见)。