Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add help button, but keep maximize and minimize

Tags:

c#

winforms

I would like to be able to add the help button onto my winform, but keep the maxmimize and minimize buttons, but windows standard is to disable both to be able to show the help button.

There is already a question similar: How to include help '?' in title bar of winform - but in that question the one who asked the question is content with removing those 2 buttons for the help to show.

Is there away that i can have help, max, min and close buttons all there at the same time?

Thanks.

like image 684
Axxelsian Avatar asked Jun 21 '12 14:06

Axxelsian


2 Answers

Windows doesn't support showing both. A workaround is to provide your own button to trigger the same action. Put it somewhere close to the upper right corner. You trigger this by sending yourself a WM_SYSCOMMAND message, just like the standard help button does. Like this:

    private void Help_Click(object sender, EventArgs e) {
        Help.Capture = false;
        SendMessage(this.Handle, WM_SYSCOMMAND, (IntPtr)SC_CONTEXTHELP, IntPtr.Zero);
    }

    private const int WM_SYSCOMMAND = 0x112;
    private const int SC_CONTEXTHELP = 0xf180;
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);

Which assumes that button's name is "Help".

like image 71
Hans Passant Avatar answered Oct 30 '22 21:10

Hans Passant


One way to do this is to draw your own border.

FormBorderStyle = None

Now construct your own caption area. This is non trivial because you have to handle drag resize events, transparency if you want rounded corners, etc.

like image 37
RQDQ Avatar answered Oct 30 '22 20:10

RQDQ