C# 在 WPF 中使用 F1 帮助(CHM 格式)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/928122/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 03:24:57  来源:igfitidea点击:

Using F1 Help (CHM format) With WPF

c#wpfwinformsinteropchm

提问by phyllis diller

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.

我已经在 WPF 应用程序上工作了一段时间,现在是时候将 CHM 格式的帮助文档附加到它上面了。

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.

可惜!HelpProvider,在 Winforms 中显示 CHM 文件的标准方式,已经神奇地消失了,并且在 WPF 中没有对应物。我一直在尝试使用 WindowsFormsHost 生成一个新控件,以便我可以实际显示帮助,但本质上它只是获取对整个 UI 的控制。

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

更详细一点:我有一个菜单项,我想在单击时打开 CHM 文件。

First I set up the WindowsFormsHost...

首先我设置了 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.

我不确定从哪里开始。当我显示 helpForm 时,它会隐藏/覆盖现有的 UI,我得到的只是一个灰色的空 WPF 窗口,没有帮助文件。

Any takers?

有接班人吗?

采纳答案by Scott Anderson

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

叫我疯了,但你不能这样做:

System.Diagnostics.Process.Start(@"C:\path-to-chm-file.chm");

回答by jitter

How about using the Helpclass instead of opening the file externally

如何使用Help类而不是从外部打开文件

回答by Cameron MacFarland

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

如果您包含 System.Windows.Forms.dll,您还可以执行以下操作:

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

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

此外,还有一篇文章在这里增加一个上下文敏感的帮助系统,WPF。

回答by Peter M

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!

我正在尝试使用 WPF 的 Easy Help,它还解决了基于关键字的上下文相关帮助。目前看来还不错。我需要做的就是破解并写一些像样的帮助!

回答by Dzmitry Lahoda

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

您可以使用http://www.pinvoke.net/default.aspx/hhctrl.HtmlHelp打开指定主题的 chm 帮助并更好地控制 chm 窗口的显示方式。