如何使用System.Windows.Forms.Help.ShowHelp()控制帮助窗口的大小?

我有一个用C#编写的WPF 4.0应用程序,目前正在使用System.Windows.Forms.Help.ShowHelp()来显示应用程序的Windows帮助文件。

我希望能够在打开时控制帮助查看器的初始大小。 目前,它默认为最近使用的大小。

我怎样才能做到这一点?

这是可能的。 在项目中添加一个类并粘贴以下代码:

 using System; using System.Text; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Diagnostics; static class Utils { public static void MoveHelpWindow(Rectangle rc) { EnumThreadWndProc callback = (hWnd, lp) => { // Check if this is the help window StringBuilder sb = new StringBuilder(260); GetClassName(hWnd, sb, sb.Capacity); if (sb.ToString() != "HH Parent") return true; MoveWindow(hWnd, rc.Left, rc.Top, rc.Width, rc.Height, false); return false; }; foreach (ProcessThread pth in Process.GetCurrentProcess().Threads) { EnumThreadWindows(pth.Id, callback, IntPtr.Zero); } } // P/Invoke declarations private delegate bool EnumThreadWndProc(IntPtr hWnd, IntPtr lp); [DllImport("user32.dll")] private static extern bool EnumThreadWindows(int tid, EnumThreadWndProc callback, IntPtr lp); [DllImport("user32.dll")] private static extern int GetClassName(IntPtr hWnd, StringBuilder buffer, int buflen); [DllImport("user32.dll")] private static extern bool MoveWindow(IntPtr hWnd, int x, int y, int w, int h, bool repaint); } 

你像这样使用它,BeginInvoke调用很重要:

 Help.ShowHelp(this, @"file://c:\windows\help\bcmwlhlp.chm"); this.BeginInvoke(new MethodInvoker(() => Utils.MoveHelpWindow(new Rectangle(0, 0, 300, 200)))); 

你不能这样做,但正如ChrisF在评论中提到的,你可以删除用户设置。 它们存储在Documents and Settings \%username%\ Application Data \ Microsoft \ HTML Help下

看看这个post’ 如何清除HTML HELP的初始状态? “

如果要修改默认值,请使用HTMLHelp workshop