Share via


Adding Help Content (Visual Basic .NET Tutorial) [Office 2003 SDK Documentation]

Previous  Adding Command Buttons

In this section you will add two portions of Help text to the SimpleSample smart document. The first portion displays the Help globally for all elements and is attached to the top-level example element. The second portion displays Help text for the help element.

  1. The first thing you need to do is add a constant for the <example> and help elements in the SimpleSample schema. Insert the following code into the general declarations section of your code module, below the existing constants.

    Const cEXAMPLE As String = cNAMESPACE & "#example"
    Const cHELP As String = cNAMESPACE & "#help"
    
  2. Next, you need to add 2 to the cTYPES constant. Remove the existing cTYPES constant and enter the following code, or change your code to match.

    Const cTYPES As Integer = 4
    
  3. You also need to add a path constant that contains the path of your smart document solution. In the case of the SimpleSample smart document, the path is stored to a local computer. However, you can also host it on a Web server or store it in a shared network location. Insert the following code into the general declarations section of your code module. You will specify the path to use in the SmartDocInitialize subroutine.

    Private strPath  As String
    
  4. You need to add a reference to the Microsoft Word 11.0 Object Library. After you add the type library from the Add Reference dialog box, place the following code at the beginning of the code module, below the Smart Tag type library imports statement.

    Imports Microsoft.Office.Interop.Word
    
  5. To get a pointer to the location of the Help files, you need to specify the folder. However, because you may not know where the files are on a user's local computer, the following code uses a relative path based on the path in the smart document's Document object. Insert the following code in the SmartDocInitialize subroutine that you added earlier.

        Dim objDoc As Microsoft.Office.Interop.Word.Document
        objDoc = Document
        strPath = objDoc.Path & "\"
    
  6. Now you are ready to modify the existing code to insert the Help text. The properties you need to modify are SmartDocXMLTypeName, SmartDocXMLTypeCaption, ControlCount, ControlID, ControlTypeFromID, and ControlCaptionFromID.

    In the SmartDocXMLTypeName property, insert the following code.

            Case 3
                SmartDocXmlTypeName = cEXAMPLE
            Case 4
                SmartDocXmlTypeName = cHELP
    

    In the SmartDocXMLTypeCaption property, insert the following code.

            Case 3
                SmartDocXmlTypeCaption = "Global Help text"
            Case 4
                SmartDocXmlTypeCaption = "Help text"
    

    In the ControlCount property, insert the following code.

            Case cEXAMPLE
                ControlCount = 1
            Case cHELP
                ControlCount = 1
    

    In the ControlID property, insert the following code.

            Case cEXAMPLE
                ControlID = ControlIndex + 200
            Case cHELP
                ControlID = ControlIndex + 300
    

    In the ControlTypeFromID property, insert the following code. When you specify the control type, use C_TYPE_HELP to specify Help content that is in the code and is passed as a string; use C_TYPE_HELPURL to specify Help content that is pulled from an external file and is passed as a file path. Help content, whether contained in the code or in an external file, should be well-formed HTML or XHTML.

            Case 201
                ControlTypeFromID = C_TYPE.C_TYPE_HELP
            Case 301
                ControlTypeFromID = C_TYPE.C_TYPE_HELPURL
    

    In the ControlCaptionFromID property, insert the following code.

            Case 201
                ControlCaptionFromID = _
                    "Help text applies to all elements."
            Case 301
                ControlCaptionFromID = _
                    "Help text applies only to the help element."
    
  7. Now you will add the code to populate the Help text. Use the PopulateHelpContent method to specify Help content. As noted above, one of the Help portions is specified using C_TYPE_HELP, and the other is C_TYPE_HELPURL. Insert the following code into the PopulateHelpContent method subroutine.

    Note  Not all HTML elements are supported for Help content that is displayed in the Document Actions task pane. For information about the elements that are supported, see Formatting HTML Help Content.

        Select Case ControlID
            Case 201
                Content = "<html><body><p>This is the SimpleSample " & _
                    "smart document.</p></body></html>"
            Case 301
                Content = strPath & "help.htm"
        End Select
    
  8. Recompile your SimpleSample smart document DLL, and copy it to the deployment location that you specified earlier. When you reopen your SimpleSample smart document, delete the SimpleSample XML expansion pack, and then re-add it to the document.

Next   Adding Radio Buttons