Back to Devexpress

ActiveX Controls in Rich Text Documents

windowsforms-403135-controls-and-libraries-rich-text-editor-rich-edit-control-document-active-x-controls-in-rich-text-documents.md

latest4.4 KB
Original Source

ActiveX Controls in Rich Text Documents

  • Dec 24, 2021
  • 2 minutes to read

The WinForms Rich Text Editor allows you view, print, and export documents with ActiveX controls to PDF. You can retrieve ActiveX controls from a document, obtain control properties, or delete these controls.

Important

The Rich Text Editor displays ActiveX controls as images. You cannot run macros associated with ActiveX controls.

Supported Formats

The WinForms Rich Text Editor supports ActiveX controls in following file formats:

  • DOCX
  • DOCM
  • DOC
  • DOT
  • DOTX
  • DOTM
  • RTF
  • PDF (export only)

If a DOC file is encrypted, the Rich Text Editor loads and saves ActiveX controls as images.

Access ActiveX Controls

ActiveX controls are stored in ShapeCollection returned by the SubDocument.Shapes property. Use the ShapeCollection.Item property to return an individual control (a Shape object) from the collection. The Shape.Type property helps you determine a drawing object type. This property returns the ActiveXControl value for an ActiveX control.

The Shape.ActiveXFormat property allows you to obtain the following ActiveX control properties:

PropertyDescription
NameReturns the control’s name.
ControlTypeReturns the control’s type.
ProgIdReturns the programmatic identifier associated with the control.

The following example retrieves all text box controls from the document:

csharp
using DevExpress.XtraRichEdit.API.Native;
using System.Linq;
// ...

Document document = richEditControl1.Document;
List<Shape> textBoxes = document.Shapes
.Where(x => x.Type == ShapeType.ActiveXControl && 
x.ActiveXFormat.ControlType == ActiveXControlType.TextBox)
.ToList();
vb
Imports DevExpress.XtraRichEdit.API.Native
Imports System.Linq
' ...

Dim document As Document = richEditControl1.Document
Dim textBoxes As List(Of Shape) = document.Shapes _
.Where(Function(x) x.Type = ShapeType.ActiveXControl AndAlso _
x.ActiveXFormat.ControlType = ActiveXControlType.TextBox) _
.ToList()

Remove ActiveX Controls

Use one of the following methods to remove an ActiveX control from the document:

The following example removes all ActiveX controls from the collection:

csharp
Document document = richEditControl1.Document;
ShapeCollection shapes = document.Shapes;
for (int i = shapes.Count - 1; i >= 0; i--)
{
    if (shapes[i].Type == ShapeType.ActiveXControl)
        shapes.Remove(shapes[i]);
}
vb
Dim document As Document = richEditControl1.Document
Dim shapes As ShapeCollection = document.Shapes
For i As Integer = shapes.Count - 1 To 0 Step -1
    If shapes(i).Type = ShapeType.ActiveXControl Then
        shapes.Remove(shapes(i))
    End If
Next i

See Also

Shapes, Pictures, and Other Graphic Objects in Rich Text Documents

OLE Objects in Rich Text Documents