Skip to content

Commit fb1278c

Browse files
Merge pull request #282 from VijayadharshiniMathiyalagan/ES-903464-How-to-add-a-checkbox-content-control-with-a-tick-mark-in-a-Word-document
Add sample for add check box content control
2 parents 3cceaee + b06f832 commit fb1278c

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35417.141 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add-tick-mark-checkbox", "Add-tick-mark-checkbox\Add-tick-mark-checkbox.csproj", "{DDE6F50A-B79C-422F-80D3-21249A81D1EC}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{DDE6F50A-B79C-422F-80D3-21249A81D1EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{DDE6F50A-B79C-422F-80D3-21249A81D1EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{DDE6F50A-B79C-422F-80D3-21249A81D1EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{DDE6F50A-B79C-422F-80D3-21249A81D1EC}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Add_tick_mark_checkbox</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Output\.gitkeep">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
</ItemGroup>
20+
21+
22+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)