Share via


Adding Help Content (C# Tutorial) [Office 2003 SDK Documentation]

Previous  Adding Command Buttons

In this section, you 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 String cEXAMPLE = cNAMESPACE + "#example";
    const String cHELP = 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 Int32 cTYPES = 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 specify the path to use in the SmartDocInitialize subroutine.

    private String strPath;
    
  4. To get a pointer to the location of the Help files, you need to specify the folder. However, because you might not know where the files are on a user's local computer, you use 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.

    Note  You need to add a reference to the Microsoft Word 11.0 Object Library.

             Microsoft.Office.Interop.Word.Document objDoc;
    
             objDoc = (Microsoft.Office.Interop.Word.Document)Document;
             strPath = objDoc.Path + "\\";
    
  5. Now you are ready to modify the existing code to insert the Help text. The subroutines you need to modify are SmartDocXMLTypeName, SmartDocXMLTypeCaption, ControlCount, ControlID, ControlTypeFromID, and ControlCaptionFromID.

    In the SmartDocXMLTypeName property subroutine, insert the following code.

                case 3:
                   strTypeName = cEXAMPLE;
                   break;
    
                case 4:
                   strTypeName = cHELP;
                   break;
    

    In the SmartDocXMLTypeCaption property subroutine, insert the following code.

                case 3:
                   strTypeCaption = "Global Help text";
                   break;
    
                case 4:
                   strTypeCaption = "Help text";
                   break;
    

    In the ControlCount property subroutine, insert the following code.

                case cEXAMPLE:
                   intNumberOfControls = 1;
                   break;
    
                case cHELP:
                   intNumberOfControls = 1;
                   break;
    

    In the ControlID property subroutine, insert the following code.

                case cEXAMPLE:
                   intControlID = ControlIndex + 200;
                   break;
    
                case cHELP:
                   intControlID = ControlIndex + 300;
                   break;
    

    In the ControlTypeFromID property subroutine, 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:
                   type = C_TYPE.C_TYPE_HELP;
                   break;
    
                case 301:
                   type = C_TYPE.C_TYPE_HELPURL;
                   break;
    

    In the ControlCaptionFromID property subroutine, insert the following code.

                case 201:
                   strControlCaption = 
                      "Help text applies to all elements.";
                   break;
    
                case 301:
                   strControlCaption = 
                      "Help text applies only to the help element.";
                   break;
    
  6. Now you 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 by 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 displayed in the Document Actions task pane. For information about the elements that are supported, see Formatting HTML Help Content.

             switch (ControlID)
             {
                 case 201:
                    Content = "<html><body><p>This is the SimpleSample " +
                       "Smart Document.</p></body></html>";
                       break;
    
                 case 301:
                    Content = strPath + "help.htm";
                       break;
    
                 default:
                    break;
             }
    
  7. 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