Adding Check Boxes (Visual Basic 6.0 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.
The first thing you need to do is add a constant for the checkbox element. Insert the following code into the general declarations section of your code module below the existing constants.
Const cCHECKBOX As String = cNAMESPACE & "#checkbox"
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
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 ISmartDocument_SmartDocXmlTypeName = cCHECKBOX
In the SmartDocXMLTypeCaption property, insert the following code.
Case 6 ISmartDocument_SmartDocXmlTypeCaption = "Checkboxes"
In the ControlCount property, insert the following code.
Case cCHECKBOX ISmartDocument_ControlCount = 2
In the ControlID property, insert the following code.
Case cCHECKBOX ISmartDocument_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 ISmartDocument_ControlTypeFromID = C_TYPE_CHECKBOX
In the ControlCaptionFromID property, insert the following code. Again, you are adding two check boxes, so you need two captions. Note that the code checks to see the application in which the smart document is displayed and shows a different caption depending on the host application.
Case 501 If ApplicationName = "Word.Application.11" Then ISmartDocument_ControlCaptionFromID = _ "Show/Hide paragraph marks." ElseIf ApplicationName = "Excel.Application.11" Then ISmartDocument_ControlCaptionFromID = _ "Show/Hide status bar" End If Case 502 If ApplicationName = "Word.Application.11" Then ISmartDocument_ControlCaptionFromID = _ "Show/Hide XML tags." ElseIf ApplicationName = "Excel.Application.11" Then ISmartDocument_ControlCaptionFromID = _ "Show/Hide active list border" End If
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
The OnCheckboxChange method specifies what happens when a user clicks the 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 objView As Word.View Select Case ControlID Case 501 If Target.Application.Name = "Microsoft Word" Then Set objView = Word.ActiveWindow.View objView.ShowAll = Checked Else Target.Application.DisplayStatusBar = Checked End If Case 502 If Target.Application.Name = "Microsoft Word" Then Set objView = Word.ActiveWindow.View objView.ShowXMLMarkup = wdToggle Else Target.Application.ActiveWorkbook _ .InactiveListBorderVisible = Checked End If End Select
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.