Aspose::Words::DocumentBuilder::InsertCheckBox method

DocumentBuilder::InsertCheckBox(const System::String&, bool, int32_t) method

Inserts a checkbox form field at the current position.

System::SharedPtr<Aspose::Words::Fields::FormField> Aspose::Words::DocumentBuilder::InsertCheckBox(const System::String &name, bool checkedValue, int32_t size)
ParameterTypeDescription
nameconst System::String&The name of the form field. Can be an empty string. The value longer than 20 characters will be truncated.
checkedValueboolChecked status of the checkbox form field.
sizeint32_tSpecifies the size of the checkbox in points. Specify 0 for MS Word to calculate the size of the checkbox automatically.

ReturnValue

The form field node that was just inserted.

Remarks

If you specify a name for the form field, then a bookmark is automatically created with the same name.

Examples

Shows how to insert checkboxes into the document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

// Insert checkboxes of varying sizes and default checked statuses.
builder->Write(u"Unchecked check box of a default size: ");
builder->InsertCheckBox(String::Empty, false, false, 0);
builder->InsertParagraph();

builder->Write(u"Large checked check box: ");
builder->InsertCheckBox(u"CheckBox_Default", true, true, 50);
builder->InsertParagraph();

// Form fields have a name length limit of 20 characters.
builder->Write(u"Very large checked check box: ");
builder->InsertCheckBox(u"CheckBox_OnlyCheckedValue", true, 100);

ASSERT_EQ(u"CheckBox_OnlyChecked", doc->get_Range()->get_FormFields()->idx_get(2)->get_Name());

// We can interact with these check boxes in Microsoft Word by double clicking them.
doc->Save(ArtifactsDir + u"DocumentBuilder.InsertCheckBox.docx");

See Also

DocumentBuilder::InsertCheckBox(const System::String&, bool, bool, int32_t) method

Inserts a checkbox form field at the current position.

System::SharedPtr<Aspose::Words::Fields::FormField> Aspose::Words::DocumentBuilder::InsertCheckBox(const System::String &name, bool defaultValue, bool checkedValue, int32_t size)
ParameterTypeDescription
nameconst System::String&The name of the form field. Can be an empty string. The value longer than 20 characters will be truncated.
defaultValueboolDefault value of the checkbox form field.
checkedValueboolCurrent checked status of the checkbox form field.
sizeint32_tSpecifies the size of the checkbox in points. Specify 0 for MS Word to calculate the size of the checkbox automatically.

ReturnValue

The form field node that was just inserted.

Remarks

If you specify a name for the form field, then a bookmark is automatically created with the same name.

Examples

Shows how to insert checkboxes into the document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

// Insert checkboxes of varying sizes and default checked statuses.
builder->Write(u"Unchecked check box of a default size: ");
builder->InsertCheckBox(String::Empty, false, false, 0);
builder->InsertParagraph();

builder->Write(u"Large checked check box: ");
builder->InsertCheckBox(u"CheckBox_Default", true, true, 50);
builder->InsertParagraph();

// Form fields have a name length limit of 20 characters.
builder->Write(u"Very large checked check box: ");
builder->InsertCheckBox(u"CheckBox_OnlyCheckedValue", true, 100);

ASSERT_EQ(u"CheckBox_OnlyChecked", doc->get_Range()->get_FormFields()->idx_get(2)->get_Name());

// We can interact with these check boxes in Microsoft Word by double clicking them.
doc->Save(ArtifactsDir + u"DocumentBuilder.InsertCheckBox.docx");

See Also