tags:

views:

826

answers:

4

In my program, im using the WndProc override to stop my form being resized. Thing is, the cursor is still there when you move the pointer to the edge of the form. Is there anyway to hide this cursor?

+7  A: 

Why not set the FormBorderStyle property appropriately instead? Then you don't need to use WndProc either.

Here's some sample code to demonstrate - click the button to toggle whether or not the form can be resized:

using System;
using System.Windows.Forms;
using System.Drawing;

class Test
{   
    [STAThread]
    static void Main(string[] args)
    {
        Button button = new Button 
        {
            Text = "Toggle border",
            AutoSize = true,
            Location = new Point(20, 20)
        };
        Form form = new Form
        {
            Size = new Size (200, 200),
            Controls = { button },
            FormBorderStyle = FormBorderStyle.Fixed3D
        };
        button.Click += ToggleBorder;
        Application.Run(form);
    }

    static void ToggleBorder(object sender, EventArgs e)
    {
        Form form = ((Control)sender).FindForm();
        form.FormBorderStyle = form.FormBorderStyle == FormBorderStyle.Fixed3D
            ? FormBorderStyle.Sizable : FormBorderStyle.Fixed3D;
    }
}
Jon Skeet
i have it set to resizeable toolbox because in vista, you get that nice border around it. using fixed 3d, you dont get that border (i set controlBox to false and no title)
Ozzy
Assuming you mean SizeableToolWindow, have you tried FixedToolWindow? It looks exactly the same to me, just not resizeable.
Jon Skeet
Downvoters: please explain, so the answer can be improved.
Jon Skeet
Only when its set to resizeable does the border appear when controlbox is false and text is ""
Ozzy
+2  A: 

I have found a way using WndProc thanks to the link Lasse sent me. Thanks for your reply Jon but it wasnt exactly what i wanted. For those who want to no how i did it, i used this :

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

    switch (message.Msg)
    {
        case WM_NCHITTEST:
            return;
            break;
    }

    base.WndProc(ref message);
}

i havent tested it thoroughly so dont no if there are any sideeffects but it works fine for me at the moment :)

Ozzy
I was about to answer something like that when you posted, glad you found your answer. You don't need a break after the return though.
Nazgulled
yea, your right. force of habit ^_^
Ozzy
A: 

Just setting FormBorderStyle is enough for this. Why are you using WndProc for this?

danish
because in this case formborderstyle is not enough.
Ozzy
A: 

@Ozzy / Lasse Worked for me!

Had the same problem:

Standard border styles don't give the look I want, custom CreateParams do. I specified the same values for Size, MinimumSize and MaximumSize to disable resizing. The resize cursors were still being set though, thanks to Ozzy & Lasse this is now handled by filtering WM_NCHITTEST...

Thanks

dalek9