Skip to content

Commit 60945e7

Browse files
Modified the code logic
1 parent dcde7e4 commit 60945e7

File tree

1 file changed

+28
-14
lines changed
  • Content-Controls/Add-tick-mark-checkbox/Add-tick-mark-checkbox

1 file changed

+28
-14
lines changed

Content-Controls/Add-tick-mark-checkbox/Add-tick-mark-checkbox/Program.cs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,44 @@
66

77
using (WordDocument wordDocument = new WordDocument())
88
{
9-
// Add a section & a paragraph in the empty document
9+
// Add a section and paragraph to initialize an empty document structure
1010
wordDocument.EnsureMinimal();
11-
// Append an inline content control for the tick checkbox
12-
IInlineContentControl tickInline = wordDocument.LastParagraph.AppendInlineContentControl(ContentControlType.CheckBox);
13-
// Create a CheckBoxState for the tick symbol
11+
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);
16+
// Create a CheckBoxState for the checked state, using a tick symbol in the Wingdings font
1417
CheckBoxState tickState = new CheckBoxState
1518
{
1619
Font = "Wingdings",
17-
Value = "\uF0FE" // Unicode for tick symbol (✓) in Wingdings
20+
Value = "\uF0FE" // Unicode for the tick symbol (✓) in Wingdings
1821
};
19-
// Set the checked state of the tick checkbox content control
20-
tickInline.ContentControlProperties.CheckedState = tickState;
21-
// Create a CheckBoxState for the unchecked state (empty box)
22+
// Set the checked state of the checkbox content control to display the tick symbol when selected
23+
checkInline.ContentControlProperties.CheckedState = tickState;
24+
// Create a CheckBoxState for the unchecked state, using an empty box symbol in the Wingdings font
2225
CheckBoxState uncheckedState = new CheckBoxState
2326
{
2427
Font = "Wingdings",
25-
Value = "\uF0A8" // Unicode for empty box in Wingdings
28+
Value = "\uF0A8" // Unicode for the empty box symbol in Wingdings
2629
};
27-
// Set the unchecked state of the tick checkbox content control
28-
tickInline.ContentControlProperties.UncheckedState = uncheckedState;
29-
// Set the initial state of the tick checkbox as checked
30-
tickInline.ContentControlProperties.IsChecked = true;
30+
// Set the unchecked state of the checkbox content control to display an empty box when not selected
31+
checkInline.ContentControlProperties.UncheckedState = uncheckedState;
32+
// Set the initial state of the "Female" checkbox to checked
33+
checkInline.ContentControlProperties.IsChecked = true;
34+
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);
39+
// Set the checked and unchecked states.
40+
uncheckInline.ContentControlProperties.CheckedState = tickState;
41+
uncheckInline.ContentControlProperties.UncheckedState = uncheckedState;
42+
// 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
3145
using (FileStream outputStream1 = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.OpenOrCreate, FileAccess.ReadWrite))
3246
{
3347
wordDocument.Save(outputStream1, FormatType.Docx);
3448
}
35-
}
49+
}

0 commit comments

Comments
 (0)