Share via


Adding Check Boxes (Visual Basic .NET Tutorial) [Office 2003 SDK Documentation]

Previous  Adding Radio Buttons

The following steps show you how to add a check box to the SimpleSample smart document.

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

    Const cCHECKBOX As String = cNAMESPACE & "#checkbox"
    
  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 = 6
    
  3. Now you are ready to modify the existing code to insert the check boxes. The subroutines you need to modify are SmartDocXMLTypeName, SmartDocXMLTypeCaption, ControlCount, ControlID, ControlTypeFromID, and ControlCaptionFromID.

    In the SmartDocXMLTypeName property, insert the following code.

            Case 6
                SmartDocXmlTypeName = cCHECKBOX
    

    In the SmartDocXMLTypeCaption property, insert the following code.

            Case 6
                SmartDocXmlTypeCaption = "Checkboxes"
    

    In the ControlCount property, insert the following code.

            Case cCHECKBOX
                ControlCount = 2
    

    In the ControlID property, insert the following code.

            Case cCHECKBOX
                ControlID = ControlIndex + 500
    

    In the ControlTypeFromID property, insert the following code. You are adding two check boxes to the SimpleSample smart document, so you need to add two check box controls.

            Case 501, 502
                ControlTypeFromID = C_TYPE.C_TYPE_CHECKBOX
    

    In the ControlCaptionFromID property, insert the following code. Again, you are adding two check boxes, so you need two captions.

            Case 501
                ControlCaptionFromID = _
                    "Show/Hide paragraph marks."
            Case 502
                ControlCaptionFromID = _
                    "Show/Hide XML tags."
    
  4. The PopulateCheckbox method specifies the initial state of the check boxes. For the two check boxes in the SimpleSample smart document, the initial state is checked, as shown in the following code.

        Select Case ControlID
            Case 501, 502
                Checked = True
        End Select
    
  5. The OnCheckboxChange method specifies what happens when a user clicks a check box. In the SimpleSample smart document, when the user selects or clears one of the check boxes, a Microsoft Word option is turned on or off.

            Dim objDoc As Microsoft.Office.Interop.Word.Document
            Dim objView As Microsoft.Office.Interop.Word.View
    
            objDoc = Target.Document
            objView = objDoc.ActiveWindow.View
    
            Select Case ControlID
                Case 501
                    objView.ShowAll = Not objView.ShowAll
                Case 502
                    objView.ShowXMLMarkup = Not objView.ShowXMLMarkup
            End Select
    
  6. 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 List Boxes and Combo Boxes