Add help button, but keep maximize and minimize

后端 未结 2 1653
梦毁少年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".

提交回复
热议问题