Search code examples
c#winformsnonclient-area

Best way to customize winforms frame?


I would like to draw some simple rectangles and text over the window frame so it looks like Visual Studio. Can it be done or should i make a borderless window and handle moving andresizing myself?

EDIT: I wrote this. But how do I draw now?

protected override void WndProc(ref Message m)
{
    if (m.Msg == WndProcMsg.WM_PAINT) //0x000f
    {

    }
    base.WndProc(ref m);
}

Solution

  • https://learn.microsoft.com/en-us/windows/desktop/dwm/customframe works great. It was traslated to C# by @Chris Taylor. You can download the project from his OneDrive

    Just fix case Win32Messages.WM_NCHITTEST with:

    int ht = NCHitText(m);
    if (callDWP) 
    { 
       callDWP = (ht == Win32Constants.HTNOWHERE);
        result = new IntPtr(ht);
    }