Marek Javůrek
Marek Javůrek

Reputation: 965

c#, hide "controlbox", winforms

I just don't know how to explain my problem. So I have created an image.

(I am not using WPF)


So now I have problem connected with my old problem.

Now I have the new "cool" border around my form.

But it is working only when I use FormBorderStyle.SizableToolWindow or FormBorderStyle.Sizable otherwise it is "borderless".

But I wanna have non-resizable form...

My poor solution:

I can use maximumsize = this.size; and minimumsize = this.size but when I put my cursor over the border then my cursor changes to "resize" cursor... and that is ugly...

I hope you will understand me.

Thanks

Upvotes: 2

Views: 4778

Answers (1)

BoltClock
BoltClock

Reputation: 724342

You need to set your form to have no title and also to, as you say, hide the control box. You can change both of these in the Properties panel for your form.

Or, in code:

public Form1()
{
    InitializeComponent();

    ControlBox = false;
    Text = "";
}

Note that this will cause your form to be undraggable (if it's not already resizable), and you need to add your own control to handle closing the form.

EDIT: one way to prevent the window from being resizable and prevent the cursor from changing to the resize handles is to override the WndProc() handler for the form and intercept WM_NCHITTEST.

Place this method in your form class, and keep the FormBorderStyle as FormBorderStyle.Sizable or FormBorderStyle.SizableToolWindow:

protected override void WndProc(ref Message message) 
{ 
    const int WM_NCHITTEST = 0x0084; 

    if (message.Msg == WM_NCHITTEST)
    {
        return; 
    }

    base.WndProc(ref message);
}

Upvotes: 7

Related Questions