Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stop a double click of the window title bar from maximizing a window of FormBorderStyle.FixedToolWindow?

Tags:

c#

winforms

I'm annoyed that the I'm promised a fixed window that the user can't resize, but then of course they're allowed to double click the title bar to maximize this 'unresizable' window. How can I turn this off? Can I do it with winforms code, or must I go down to Win32?

Thanks!

like image 417
Isaac Bolinger Avatar asked Mar 06 '12 17:03

Isaac Bolinger


4 Answers

You could set the MaximizeBox property of the form to false

like image 171
ionden Avatar answered Oct 22 '22 15:10

ionden


You can disable the double-click message on a title bar in general (or change the default behavior which is maximizing the window). it works on any FormBorderStyle:

private const int WM_NCLBUTTONDBLCLK = 0x00A3; //double click on a title bar a.k.a. non-client area of the form

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_NCLBUTTONDBLCLK)
            {
                m.Result = IntPtr.Zero;
                return;
            }
            base.WndProc(ref m);
        }

MSDN Source

Cheers!

like image 40
LazyZebra Avatar answered Oct 22 '22 16:10

LazyZebra


/// /// This is we are overriding base WIN32 window procedure to prevent the form from being moved by the mouse as well as resized by the mouse double click. /// ///

    protected override void WndProc(ref Message m)
    {
        const int WM_SYSCOMMAND = 0x0112;
        const int SC_MOVE = 0xF010;
        const int WM_NCLBUTTONDBLCLK = 0x00A3; //double click on a title bar a.k.a. non-client area of the form

        switch (m.Msg)
        {
            case WM_SYSCOMMAND:             //preventing the form from being moved by the mouse.
                int command = m.WParam.ToInt32() & 0xfff0;
                if (command == SC_MOVE)
                    return;
                break;
        }

       if(m.Msg== WM_NCLBUTTONDBLCLK)       //preventing the form being resized by the mouse double click on the title bar.
        {
            m.Result = IntPtr.Zero;                   
            return;                   
        }

        base.WndProc(ref m);
    }
like image 9
ismail Avatar answered Oct 22 '22 14:10

ismail


I know I'm late to the party, May help someone who is searching for the same.

private const int WM_NCLBUTTONDBLCLK = 0x00A3; //double click on a title bar a.k.a. non-client area of the form

private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{

    switch (msg)
    {                
        case WM_NCLBUTTONDBLCLK:    //preventing the form being resized by the mouse double click on the title bar.
            handled = true;
            break;                
        default:
            break;
    }
    return IntPtr.Zero;
}
like image 3
Gopichandar Avatar answered Oct 22 '22 14:10

Gopichandar