Sizable App Without Border (FormBorderStyle=Sizable)

218 views Asked by At

How do I hide the default window (form) border (I want to use mine), but still have the snapping and form shadow available?

Developing on (Desktop) Win 8, thought it's DWM API function or something like it.

PS: I'm new to DWM.

1

There are 1 answers

0
VentyCZ On

Ok, I finally found a solution for my problem.

Originally I was using WinForms, but over the years I changed over to WPF.

WPF got something called WindowChrome, which is the Window frame/holder that holds the Window contents & changes everytime there's a new Windows iteration.

I found out that there's a function that makes it possible to change the WindowChrome property of the Window really easily.

I made my own function, where I can pass the properties for a new 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
    });
}

I hope I made the comment easy to understand if anyone wants to use the function. Also I found out that using Thickness(-1) on glassThickness makes the whole Window have the glass underneath it wihout giving any extra space/border outside of the Window itself, but still keeping the drop shadow effect.

Another note is, that you have to change window's padding while maximizing, because Windows still want to cut off the border/glass that ain't there anymore.

PS: English isn't my native language, if there's any problem in the grammar, fix it please while editing. Thanks & yeah I'm answering my own question that is nearly 2 years old (my appologies).