如何在帮助请求模式下放置表单?

时间:2022-08-14 15:51:00

A .NET Windows form can have a help button on the title bar when the HelpButton property is set to true (and you are not displaying minimize/maximize buttons). When this help button is clicked, the form goes into a help mode where the cursor changes and clicking elsewhere in the form does not have the usual effect. Instead a click induces the HelpRequested event on the clicked control. Great, except that I need the help button AND the minimize/maximize buttons. So I have created my own help button in the client area of my form. When it is clicked, how can I place the form in help mode?

当HelpButton属性设置为true(并且您没有显示最小化/最大化按钮)时,.NET Windows窗体可以在标题栏上有一个帮助按钮。单击此帮助按钮后,表单将进入帮助模式,其中光标更改并单击表单中的其他位置不具有通常的效果。相反,单击会在单击的控件上引发HelpRequested事件。很棒,除了我需要帮助按钮和最小化/最大化按钮。所以我在表单的客户区创建了自己的帮助按钮。单击时,如何将表单置于帮助模式?

1 个解决方案

#1


1  

Found it.

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

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

#1


1  

Found it.

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

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