Skip to content

Commit 016320c

Browse files
Re-wamped the code snippet
1 parent 60945e7 commit 016320c

File tree

1 file changed

+27
-24
lines changed
  • Content-Controls/Add-tick-mark-checkbox/Add-tick-mark-checkbox

1 file changed

+27
-24
lines changed
Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,52 @@
11
using Syncfusion.DocIO.DLS;
22
using Syncfusion.DocIO;
33

4-
//Register Syncfusion license
5-
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Mgo+DSMBMAY9C3t2UlhhQlNHfV5DQmBWfFN0QXNYfVRwdF9GYEwgOX1dQl9nSXZTc0VlWndfcXNSQWc=");
6-
7-
using (WordDocument wordDocument = new WordDocument())
4+
using (WordDocument document = new WordDocument())
85
{
9-
// Add a section and paragraph to initialize an empty document structure
10-
wordDocument.EnsureMinimal();
6+
// Add one section and one paragraph to the document.
7+
document.EnsureMinimal();
118

12-
// Append the label "Gender: Female" next to the first checkbox
13-
wordDocument.LastParagraph.AppendText("Gender:\tFemale ");
14-
// Append an inline content control to add a checkbox for the checked box
15-
IInlineContentControl checkInline = wordDocument.LastParagraph.AppendInlineContentControl(ContentControlType.CheckBox);
169
// Create a CheckBoxState for the checked state, using a tick symbol in the Wingdings font
1710
CheckBoxState tickState = new CheckBoxState
1811
{
1912
Font = "Wingdings",
2013
Value = "\uF0FE" // Unicode for the tick symbol (✓) in Wingdings
2114
};
22-
// Set the checked state of the checkbox content control to display the tick symbol when selected
23-
checkInline.ContentControlProperties.CheckedState = tickState;
2415
// Create a CheckBoxState for the unchecked state, using an empty box symbol in the Wingdings font
25-
CheckBoxState uncheckedState = new CheckBoxState
16+
CheckBoxState unTickState = new CheckBoxState
2617
{
2718
Font = "Wingdings",
2819
Value = "\uF0A8" // Unicode for the empty box symbol in Wingdings
2920
};
21+
22+
// Gets the last paragraph.
23+
WParagraph paragraph = document.LastParagraph;
24+
// Add text to the paragraph.
25+
document.LastParagraph.AppendText("Gender:\tFemale ");
26+
// Append checkbox content control to the paragraph for the "checked" option.
27+
IInlineContentControl checkedCheckBox = document.LastParagraph.AppendInlineContentControl(ContentControlType.CheckBox);
28+
// Set the checked state of the checkbox content control to display the tick symbol when selected
29+
checkedCheckBox.ContentControlProperties.CheckedState = tickState;
3030
// Set the unchecked state of the checkbox content control to display an empty box when not selected
31-
checkInline.ContentControlProperties.UncheckedState = uncheckedState;
31+
checkedCheckBox.ContentControlProperties.UncheckedState = unTickState;
3232
// Set the initial state of the "Female" checkbox to checked
33-
checkInline.ContentControlProperties.IsChecked = true;
33+
checkedCheckBox.ContentControlProperties.IsChecked = true;
3434

35-
// Append a tab space and add the label "Male" for the second checkbox
36-
wordDocument.LastParagraph.AppendText("\tMale ");
37-
// Append an inline content control to add a checkbox for the unchecked option
38-
IInlineContentControl uncheckInline = wordDocument.LastParagraph.AppendInlineContentControl(ContentControlType.CheckBox);
35+
// Gets the last paragraph.
36+
paragraph = document.LastParagraph;
37+
// Add text to the paragraph.
38+
document.LastParagraph.AppendText("\tMale ");
39+
// Append checkbox content control to the paragraph for the "unchecked" option.
40+
IInlineContentControl uncheckedCheckBox = document.LastParagraph.AppendInlineContentControl(ContentControlType.CheckBox);
3941
// Set the checked and unchecked states.
40-
uncheckInline.ContentControlProperties.CheckedState = tickState;
41-
uncheckInline.ContentControlProperties.UncheckedState = uncheckedState;
42+
uncheckedCheckBox.ContentControlProperties.CheckedState = tickState;
43+
uncheckedCheckBox.ContentControlProperties.UncheckedState = unTickState;
4244
// Set the initial state of the "Male" checkbox to unchecked
43-
uncheckInline.ContentControlProperties.IsChecked = false;
44-
// Save the document to a file in DOCX format
45+
uncheckedCheckBox.ContentControlProperties.IsChecked = false;
46+
47+
// Save the document.
4548
using (FileStream outputStream1 = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.OpenOrCreate, FileAccess.ReadWrite))
4649
{
47-
wordDocument.Save(outputStream1, FormatType.Docx);
50+
document.Save(outputStream1, FormatType.Docx);
4851
}
4952
}

0 commit comments

Comments
 (0)