Adding Check Boxes (C# 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 in the SimpleSample schema. Insert the following code into the general declarations section of your code module, below the existing constants.
const String cCHECKBOX = 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 Int32 cTYPES = 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 subroutine, insert the following code.
case 6: strTypeName = cCHECKBOX; break;
In the SmartDocXMLTypeCaption property subroutine, insert the following code.
case 6: strTypeCaption = "Checkboxes"; break;
In the ControlCount property subroutine, insert the following code.
case cCHECKBOX: intNumberOfControls = 2; break;
In the ControlID property subroutine, insert the following code.
case cCHECKBOX: intControlID = ControlIndex + 500; break;
In the ControlTypeFromID property subroutine, 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: type = C_TYPE.C_TYPE_CHECKBOX; break; case 502: type = C_TYPE.C_TYPE_CHECKBOX; break;
In the ControlCaptionFromID property subroutine, insert the following code. Again, you are adding two check boxes, so you need two captions.
case 501: strControlCaption = "Show/Hide paragraph marks."; break; case 502: strControlCaption = "Show/Hide XML tags."; break;
The PopulateCheckbox method specifies the initial state of the check boxes. For the two check boxes in the SimpleSample smart document, the check boxes are initially checked, as shown in the following code.
switch (ControlID){ case 501: Checked = true; break; case 502: Checked = true; break; default: Checked = true; break; }
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.
Microsoft.Office.Interop.Word.Range objRange = (Microsoft.Office.Interop.Word.Range)Target; Microsoft.Office.Interop.Word.Document objDoc = objRange.Document; Microsoft.Office.Interop.Word.View objView = objDoc.ActiveWindow.View; switch (ControlID){ case 501: objView.ShowAll =! objView.ShowAll; break; case 502: objView.ShowXMLMarkup = (Int32)Microsoft.Office.Interop. Word.WdConstants.wdToggle; break; default: break; }
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.