How to do context help (“what is this?” button) in WinForms?

后端 未结 1 783
小鲜肉
小鲜肉 2021-01-23 01:24

How to make \"what is this?\" button like those in top-right corner of dialogue boxes. I cant set Form.HelpButton to true because I have Minimize & Maximize buttons there.

相关标签:
1条回答
  • 2021-01-23 02:03

    You can't. You either get the min/max buttons OR the help button. These are standard Windows UI guidelines, the help button should only appear on dialogs and dialogs shouldn't have min/max buttons.

    You can solve you problem with a wee bit of P/Invoke. Add a What's This button to your UI and implement its Click event like this:

    private void btnWhatsThis_Click(object sender, EventArgs e) {
      btnWhatsThis.Capture = false;
      SendMessage(this.Handle, WM_SYSCOMMAND, (IntPtr)SC_CONTEXTHELP, IntPtr.Zero);
    }
    
    private const int SC_CONTEXTHELP = 0xf180;
    private const int WM_SYSCOMMAND = 0x112;
    
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
    
    0 讨论(0)
提交回复
热议问题