开发者

Clicking on a button to display .CHM help file in VB.NET

I want to display a .CHM help file when clicking on a button in VB.NET. Could anyone show me code how to do this?

Private Sub cmdHelp_Click(ByVal sender As System.Objects, Byval e As System.EventArgs)Handles cmdHelp.Click
   'Please help provide some开发者_如何学运维 code
End Sub


The .NET API offers the Help class in the System.Windows.Forms namespace. Some examples:

Help.ShowHelp(ParentForm, "HelpFile.chm", HelpNavigator.TableofContents, Nothing)
Help.ShowHelp(ParentForm, "HelpFile.chm", HelpNavigator.Index, Nothing)
Help.ShowHelp(ParentForm, "HelpFile.chm", HelpNavigator.Topic, "Page.html")
Help.ShowHelp(ParentForm, "HelpFile.chm", HelpNavigator.TopicId, 123)
Help.ShowHelp(ParentForm, "HelpFile.chm", HelpNavigator.Keyword, "Keyword")


Doing a Process.Start with a verb of open does the trick:

Module Module1

    Sub Main()
        Dim p As New Process()
        Dim psi As New ProcessStartInfo("path to my CHM file")
        psi.Verb = "open"
        p.StartInfo = psi
        p.Start()

        Console.ReadKey()
    End Sub

End Module

Note that .chm files are heavily restricted by the OS from about WinXP SP3 (SP2?) onwards - they are considered to be a reasonble security risk, so you can't open them directly from a network or remote location. You will need to code accordingly, and expect exceptions when trying to open them.


on Button click event write this code

Dim RetVal
RetVal = Shell("hh.exe " & App.HelpFile, vbNormalFocus)

Where hh.exe is any name App.Helpfile is your chm file name


You can also use HH.EXE to display a specified topic.

In the example code replace [topicid] with the real topic id and replace [yourhelpfile.chm] with the full path and name of your .chm file

If a return value is required

Dim RetVal As Integer = Shell("HH.EXE -mapid [topicid] ms-its:[yourhelpfile.chm]", AppWinStyle.NormalFocus)

otherwise just this

Shell("HH.EXE -mapid [topicid] ms-its:[yourhelpfile.chm]", AppWinStyle.NormalFocus)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜