4

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
Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Tepken Vannkorn
  • 9,648
  • 14
  • 61
  • 86

4 Answers4

9

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")
Hand-E-Food
  • 12,368
  • 8
  • 45
  • 80
5

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.

slugster
  • 49,403
  • 14
  • 95
  • 145
1

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

Shrivallabh
  • 2,863
  • 2
  • 27
  • 47
0

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)
Jainil
  • 1,488
  • 1
  • 21
  • 26
Ray E
  • 134
  • 1
  • 9