c# – Custom Title Bar and Form Borders – Education Career Blog

I have a form that I would like to draw a custom title bar with as well as custom borders around the application to take over the form resizing. I turned off the regular title bar for the application and build my own out of a couple image which i set to anchor to the application. The issue is when the form is resized, it looks very choppy because the form doesnt resize it until after the form is painted. What would i need to do in order to smooth out the resizing of the borders. Also when i use the borders to resize the form starts blinking a lot and the resize isn’t exactly correct. It resizes, however it doesn’t resize the amount it’s supposed too. Here is an example of the code i use to resize the form with the borders.

#region formDragResize
    private Point startDrag = new Point(0, 0);
    private bool resize = false;
    private void rightSideBarMid_MouseDown(object sender, MouseEventArgs e)
    {
        this.startDrag = e.Location;
        this.resize = true;
    }

    private void rightSideBarMid_MouseUp(object sender, MouseEventArgs e)
    {
        this.resize = false;
    }

    private void rightSideBarMid_MouseMove(object sender, MouseEventArgs e)
    {
        if (this.resize)
        {
            Point p1 = new Point(e.X, e.Y);
            Point p2 = this.PointToScreen(p1);
            this.Width = p2.X - this.startDrag.X;
        }
    }
 #endregion

I am very new when it comes to form paining and such so any help is appreciated.

Thanks!

,

Assuming you’re talking about Windows Forms, You don’t want to turn off the titlebar. You leave it on, but then you handle Non-client paint messages.

However, Winforms doesn’t include non-client paint events, so you will have to override WndProc and handle the NC_* messages yourself, or use a third party library that does this.

Leave a Comment