Share via


Adding Command Buttons (Visual Basic .NET Tutorial) [Office 2003 SDK Documentation]

Previous  Creating a Smart Document Using Microsoft Visual Basic .NET

The following steps show you how to add command buttons to the SimpleSample smart document.

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

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

    Const cTYPES As Integer = 2
    
  3. Now you are ready to modify the existing code to insert the command button. The subroutines you need to modify are SmartDocXMLTypeName, SmartDocXMLTypeCaption, ControlCount, ControlID, ControlTypeFromID, and ControlCaptionFromID.

    In the SmartDocXMLTypeName property, insert the following code.

            Case 2
                SmartDocXmlTypeName = cBUTTON
    

    In the SmartDocXMLTypeCaption property, insert the following code.

            Case 2
                SmartDocXmlTypeCaption = "Click"
    

    In the ControlCount property, insert the following code.

            Case cBUTTON
                ControlCount = 1
    

    In the ControlID property, insert the following code.

            Case cBUTTON
                ControlID = ControlIndex + 100
    

    In the ControlTypeFromID property, insert the following code.

            Case 101
                ControlTypeFromID = C_TYPE.C_TYPE_BUTTON
    

    Finally, in ControlCaptionFromID property, insert the following code.

            Case 101
                ControlCaptionFromID = _
                    "Test button"
    
  4. Next, you need to enter the code that operates the button you added above. In the InvokeControl method, insert the following code. The InvokeControl method is used to specify code that you want to run for command buttons, hyperlinks, and, in Microsoft Word only, clicking document fragments.

        Select Case ControlID
            Case 101
                System.Windows.Forms.MessageBox.Show("This is an example of a button.")
            Case Else
        End Select
    
  5. 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 Help Content