|
| 1 | +using Syncfusion.DocIO.DLS; |
| 2 | +using Syncfusion.DocIO; |
| 3 | + |
| 4 | +using (WordDocument document = new WordDocument()) |
| 5 | +{ |
| 6 | + // Add one section and one paragraph to the document. |
| 7 | + document.EnsureMinimal(); |
| 8 | + |
| 9 | + // Create a CheckBoxState for the checked state, using a tick symbol in the Wingdings font |
| 10 | + CheckBoxState tickState = new CheckBoxState |
| 11 | + { |
| 12 | + Font = "Wingdings", |
| 13 | + Value = "\uF0FE" // Unicode for the tick symbol (✓) in Wingdings |
| 14 | + }; |
| 15 | + // Create a CheckBoxState for the unchecked state, using an empty box symbol in the Wingdings font |
| 16 | + CheckBoxState unTickState = new CheckBoxState |
| 17 | + { |
| 18 | + Font = "Wingdings", |
| 19 | + Value = "\uF0A8" // Unicode for the empty box symbol in Wingdings |
| 20 | + }; |
| 21 | + |
| 22 | + // Gets the last paragraph. |
| 23 | + WParagraph paragraph = document.LastParagraph; |
| 24 | + // Add text to the paragraph. |
| 25 | + paragraph.AppendText("Gender:\tFemale "); |
| 26 | + // Append checkbox content control to the paragraph for the "checked" option. |
| 27 | + IInlineContentControl checkBox = paragraph.AppendInlineContentControl(ContentControlType.CheckBox); |
| 28 | + // Set the checked state of the checkbox content control to display the tick symbol when selected |
| 29 | + checkBox.ContentControlProperties.CheckedState = tickState; |
| 30 | + // Set the unchecked state of the checkbox content control to display an empty box when not selected |
| 31 | + checkBox.ContentControlProperties.UncheckedState = unTickState; |
| 32 | + // Set the initial state of the "Female" checkbox to checked |
| 33 | + checkBox.ContentControlProperties.IsChecked = true; |
| 34 | + |
| 35 | + // Add text to the paragraph. |
| 36 | + paragraph.AppendText("\tMale "); |
| 37 | + // Append checkbox content control to the paragraph for the "unchecked" option. |
| 38 | + checkBox = paragraph.AppendInlineContentControl(ContentControlType.CheckBox); |
| 39 | + // Set the checked and unchecked states. |
| 40 | + checkBox.ContentControlProperties.CheckedState = tickState; |
| 41 | + checkBox.ContentControlProperties.UncheckedState = unTickState; |
| 42 | + // Set the initial state of the "Male" checkbox to unchecked |
| 43 | + checkBox.ContentControlProperties.IsChecked = false; |
| 44 | + |
| 45 | + // Save the document. |
| 46 | + using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.OpenOrCreate, FileAccess.ReadWrite)) |
| 47 | + { |
| 48 | + document.Save(outputStream, FormatType.Docx); |
| 49 | + } |
| 50 | +} |
0 commit comments