20

I've been working on a WPF application for a while, and the time has come to attach the CHM format help document to it.

But alas! HelpProvider, the standard way to show CHM files in Winforms, has magically vanished and has no counterpart in WPF. I've been trying to use WindowsFormsHost to spawn a new control so I can actually display the help, but essentially it just grabs control of the entire UI.

A little more detail: I've got a menu item that I want to, when clicked, open up the CHM file.

First I set up the WindowsFormsHost...

host = new System.Windows.Forms.Integration.WindowsFormsHost();
helpForm = new System.Windows.Forms.Control();
host.Child = helpForm;
host.Visibility = System.Windows.Visibility.Hidden;
this.grid1.Children.Add(host);

hp = new System.Windows.Forms.HelpProvider();
hp.HelpNamespace = "Somehelpfile.chm";
hp.SetHelpNavigator(helpForm, System.Windows.Forms.HelpNavigator.TableOfContents);

And then I say, voila, reveal yourself.

private void Help_Click(object sender, RoutedEventArgs e)
{
    host.Visibility = Visibility.Visible;
    helpForm.Show();
    hp.SetShowHelp(helpForm, true);
}  

I'm not really sure of where to proceed from here. When I show the helpForm, it obscures / overrides the existing UI and all I get is a gray, empty WPF window with no help file.

Any takers?

phyllis diller
  • 795
  • 2
  • 9
  • 21
  • Does this answer your question? [Integrating help in a WPF application](https://stackoverflow.com/questions/5116465/integrating-help-in-a-wpf-application) – StayOnTarget Apr 24 '20 at 15:05

5 Answers5

28

If you include System.Windows.Forms.dll you can also do:

System.Windows.Forms.Help.ShowHelp(null, @"help.chm");

Also, there's an article here about adding a context sensitive help system to WPF.

Cameron MacFarland
  • 70,676
  • 20
  • 104
  • 133
  • I was looking for a way to open a help file in WPF, no need for context sensitivity. This precisely solves my problem. – ford Jan 20 '12 at 22:20
  • 2
    @Cameron, you can also call up help to open on a context with this method, e.g.: System.Windows.Forms.Help.ShowHelp(null, "myHelp.chm", System.Windows.Forms.HelpNavigator.KeywordIndex, "MyKeyword"); – Ed Bayiates Aug 15 '12 at 23:11
  • Where should i add this line: System.Windows.Forms.Help.ShowHelp(null, @"help.chm"); – The King Apr 22 '14 at 10:36
24

Call me crazy, but couldn't you just do:

System.Diagnostics.Process.Start(@"C:\path-to-chm-file.chm");
Scott Arrington
  • 12,325
  • 3
  • 42
  • 54
  • 19
    I suppose the subject is for F1 help - ie context sensitive - but your solution just opens the help file – gbjbaanb Sep 16 '10 at 09:04
  • 2
    @ScottAnderson I think gbjbaanb gave a pretty good reason as to why the downvote wasn't "random." – Michael Jun 07 '13 at 14:16
  • 3
    The problem with this approach is that if you press multiple times F1 it will open the help file multiple times instead of focusing the first instance. – Alexandru Dicu Jul 21 '16 at 15:01
8

I am trying out Easy Help with WPF, which also addresses context sensitive help based on key words. So far it seems good. All I need to do is get cracking and write some decent help!

Aran Mulholland
  • 23,555
  • 29
  • 141
  • 228
Peter M
  • 7,309
  • 3
  • 50
  • 91
3

You can use http://www.pinvoke.net/default.aspx/hhctrl.HtmlHelp to open chm help at specified topic and to have more control of how chm window shown.

Dzmitry Lahoda
  • 939
  • 1
  • 13
  • 34
0

How about using the Help class instead of opening the file externally

jitter
  • 53,475
  • 11
  • 111
  • 124