开发者

How can I control the size of the help window using System.Windows.Forms.Help.ShowHelp()?

I have a WPF 4.0 application written in C# an开发者_JS百科d am currently using System.Windows.Forms.Help.ShowHelp() to show the Windows Help file for the application.

I'd like to be able to control the initial size of the help viewer when it opens. Currently it defaults to the most recently used size.

How can I achieve this?


It's possible. Add a class to your project and paste this code:

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);
}

You use it like this, the BeginInvoke call is important:

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


You cannot do that but as ChrisF mention in comment you can delete user settings. They are stored under Documents and Settings\%username%\Application Data\Microsoft\HTML Help

Check out this thread 'How to clear HTML HELP's initial state?'

If you want to modify defaults use HTMLHelp workshop

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜