Legacy ActiveX (Forms 2.0) Control Types

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 (a Forms2OleControlType value) to identify a control before casting it to one of the specific subclasses – not every Forms2OleControl is one of the five strongly-typed subclasses covered here.
  • Use GroupName to associate several OptionButtonControl instances 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 (a Forms2OleControlCollection), regardless of which subclass the container is.

Common Issues

IssueCauseFix
Casting a Forms2OleControl to CheckBoxControl throws an InvalidCastExceptionThe 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 controlsThe controls don’t share the same GroupNameSet the same GroupName value on every OptionButtonControl in the set
CommandButtonControl.Caption is emptyThe button’s caption comes from the inherited Forms2OleControl.Caption, not a CommandButtonControl-specific propertyRead 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

ClassDescription
MorphDataControlAbstract base for checkbox, combo box, list box, option button, text box, and toggle button controls
CheckBoxControlCheckbox control; extends MorphDataControl; adds Checked
OptionButtonControlOption button control; extends MorphDataControl; adds Selected
TextBoxControlText box control; extends MorphDataControl; adds Text
CommandButtonControlCommand button control; extends Forms2OleControl directly

See Also