Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the HelpProvider class to show help, UI is always behind help window

Tags:

c#

.net

winforms

I have a C# Winforms app that uses the HelpProvider class. Whenever i press F1 to bring up help, the help window will always be on top of my application, I cannot bring my application UI to the foreground. I can still interact with my UI, but the help window will remain on top.

Is this by design of HelpProvider? Or am I missing something?

like image 659
David A. Avatar asked Aug 25 '10 20:08

David A.


2 Answers

There is a solution to this issue, a bit dirty, but it works. The thing is, the help window opened by HelpProvider is always on top of its parent window control, which is determined by Control instance in first parameter of Help.ShowHelp. Even if you specify null there, the main application form is still used as parent window. To avoid this, one can create a dummy form, which will be used as a help parent form. This form will be never shown, but still, help window will be “on top” of it, effectively being NOT on top of all other application windows.

public static class AppHelp
{
   private static Form mFrmDummyHost = new Form();

   public static void ShowChm()
   {
      Help.ShowHelp(mFrmDummyHost, "my_help.chm");
   }
}

Of course, all other Help.ShowHelp overloads can be called this way as well.

Hope this helps people like me, searching for answers to never-getting-old questions ;)

like image 189
Jen-Ari Avatar answered Sep 19 '22 02:09

Jen-Ari


It is indeed by design, and its something that i did not realise. I have just recompiled my final year project and confirmed it. I have read up about it and basically the help file is set to TopMost=True every time the form is clicked. This means even if you code your form to be TopMost, as soon as you click the help file it will go back on top again.

I do believe if you use start process, it should get around the issue at the loss of some customisability the help provider gives.

private void textBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
  if(e.KeyCode ==Keys.F1)
  {
    System.Diagnostics.Process.Start(@"C:\WINDOWS\Help\mspaint.chm");
  }
}

Hope it helps

like image 36
JonWillis Avatar answered Sep 22 '22 02:09

JonWillis