Add help button, but keep maximize and minimize

后端 未结 2 1654
梦毁少年i
梦毁少年i 2021-01-02 08:47

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 h

相关标签:
2条回答
  • 2021-01-02 08:59

    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".

    0 讨论(0)
  • 2021-01-02 09:12

    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.

    0 讨论(0)
提交回复
热议问题