Legacy ActiveX (Forms 2.0) Control Types
Legacy ActiveX (Forms 2.0) Control Types
Working with OLE Objects and Embedded Content covers how to reach an embedded
Microsoft Forms 2.0 ActiveX control through OleFormat.OleControl and cast it to the abstract
Forms2OleControl base class. Aspose.Words FOSS for .NET also exposes five strongly-typed
subclasses for the specific control kinds Word supports – CheckBoxControl,
OptionButtonControl, TextBoxControl, CommandButtonControl, and MorphDataControl – each
in the Aspose.Words.Drawing.Ole namespace, adding one control-specific member on top of the
properties Forms2OleControl already provides (Caption, Value, Enabled, Type,
GroupName, ForeColor, BackColor, Width, Height, Name, ChildNodes).
CheckBoxControl and OptionButtonControl
CheckBoxControl extends MorphDataControl and adds Checked (a bool) for the control’s
on/off state. OptionButtonControl also extends MorphDataControl and adds Selected (a
bool) – used for a set of mutually exclusive option buttons that share the same
GroupName.
TextBoxControl
TextBoxControl extends MorphDataControl and adds Text (a string), the control’s
displayed and editable text.
CommandButtonControl
CommandButtonControl extends Forms2OleControl directly (not MorphDataControl) and has its
own constructor. It represents a button that runs a macro when clicked in Word, with its button
label exposed through the inherited Caption property.
MorphDataControl: the Shared Base for Data-Entry Controls
MorphDataControl is an aggregate base for six related control kinds –
checkbox, combo box, list box, option button, text box, and toggle button. CheckBoxControl,
OptionButtonControl, and TextBoxControl each extend it, inheriting its members and adding
one type-specific property of their own.
Tips and Best Practices
- Read
Forms2OleControl.Type(aForms2OleControlTypevalue) to identify a control before casting it to one of the specific subclasses – not everyForms2OleControlis one of the five strongly-typed subclasses covered here. - Use
GroupNameto associate severalOptionButtonControlinstances into one mutually exclusive set, matching how Word groups option buttons. - Reach nested controls inside a frame or multi-page container through the inherited
ChildNodes(aForms2OleControlCollection), regardless of which subclass the container is.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
Casting a Forms2OleControl to CheckBoxControl throws an InvalidCastException | The control is a different Forms 2.0 control kind (for example a TextBoxControl or OptionButtonControl) | Check Forms2OleControl.Type before casting to a specific subclass |
OptionButtonControl.Selected doesn’t behave as mutually exclusive with sibling controls | The controls don’t share the same GroupName | Set the same GroupName value on every OptionButtonControl in the set |
CommandButtonControl.Caption is empty | The button’s caption comes from the inherited Forms2OleControl.Caption, not a CommandButtonControl-specific property | Read Caption, not a nonexistent CommandButtonControl-only member |
FAQ
How do I know which strongly-typed control class a Forms2OleControl actually is?
Read its Type property (Forms2OleControlType) or attempt a cast to the specific subclass
you expect, such as CheckBoxControl or TextBoxControl.
What’s the difference between MorphDataControl and Forms2OleControl?
Forms2OleControl is the abstract base for every Forms 2.0 control. MorphDataControl is a
more specific abstract base, itself extending Forms2OleControl, shared by the checkbox,
combo box, list box, option button, text box, and toggle button control kinds.
How do I read a checkbox control’s checked state?
Cast the Forms2OleControl to CheckBoxControl and read its Checked property.
Does CommandButtonControl extend MorphDataControl like the others?
No – CommandButtonControl extends Forms2OleControl directly, since a command button is not
a data-entry control.
API Reference Summary
| Class | Description |
|---|---|
MorphDataControl | Abstract base for checkbox, combo box, list box, option button, text box, and toggle button controls |
CheckBoxControl | Checkbox control; extends MorphDataControl; adds Checked |
OptionButtonControl | Option button control; extends MorphDataControl; adds Selected |
TextBoxControl | Text box control; extends MorphDataControl; adds Text |
CommandButtonControl | Command button control; extends Forms2OleControl directly |