Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Title Bar from Windows Form (Windows 10 style)

Tags:

c#

winforms

I have a very simple class which inherits from System.Windows.Forms.Form and removes the WS_CAPTION window style. It works in Windows XP & 7 perfectly. In windows 10 a piece of the titlebar is still drawn and it ends up looking ugly when using a custom titlebar control.

I know there are likely several ways to accomplish this kind of look, but I've chosen this for multiple reasons. I'm not interested in the alternative methods--that's not the intention of my question here.

My question is what is causing such a difference between the way this is rendered in windows 10 vs windows 7? The difference is not merely stylistic. It appears that the titlebar is still being rendered in some capacity even though the WS_CAPTION flag has been removed.

class BorderlessForm : System.Windows.Forms.Form
{
    protected override System.Windows.Forms.CreateParams CreateParams
    {
        get
        {
            var _CreateParams = base.CreateParams;
            _CreateParams.Style &= ~0x00C00000; // remove WS_CAPTION
            return _CreateParams;
        }
    }
}

Windows 7 screenshot (desired appearance consistent with MSDN description):

enter image description here

Windows 10 screenshot (undesirable appearance inconsistent with MSDN description):

enter image description here

like image 404
Russell Trahan Avatar asked Aug 16 '16 19:08

Russell Trahan


1 Answers

What you are observing is not a title bar but sizing border.

My question is what is causing such a difference between the way this is rendered in windows 10 vs windows 7?

The cause is different look and feel implementation on different versions of Windows.

In case you are interested how to get rid of the sizing border even on Windows 10: Remove the WS_THICKFRAME flag.

Alternatively (and perhaps more preferable) you can change your form's FormBorderStyle to some other value. Test whatever works best for you.

However there is nothing what defines the overall form border precisely. It's up to the look and feel (theme). Technically you cannot expect that form's border won't differ under different implementation. You can only ensure by testing.

like image 89
mancze Avatar answered Oct 15 '22 23:10

mancze