Inserting drawings as single objects

TX Text Control provides two different ways to insert a drawing object into a document: As a single object or multiple shapes in a drawing canvas. In the sample application, when choosing a shape type from the main menu Insert -> Shapes, the object is inserted as a single object:

In the following code, a DataVisualization.DrawingFrame object is created which hosts the WPF.Drawing.TXDrawingControl object. The DataVisualization.DrawingFrame object is added to the WPF.TextControl.Drawings collection of WPF.TextControl. Finally, a new Drawing.Shape object is added to the WPF.Drawing.TXDrawingControl object:

[C#]
TXTextControl.WPF.Drawing.TXDrawingControl drawingObject =
	new TXTextControl.WPF.Drawing.TXDrawingControl(5000, 5000);

// create a new DrawingFrame object that hosts the TXDrawingControl
TXTextControl.DataVisualization.DrawingFrame drawingFrame =
	new TXTextControl.DataVisualization.DrawingFrame(drawingObject);

// add the frame object to the Drawings collection
textControl1.Drawings.Add(drawingFrame,
	new System.Drawing.Point(0, 0),
	-1,
	TXTextControl.FrameInsertionMode.DisplaceText);

TXTextControl.Drawing.Shape newShape = new TXTextControl.Drawing.Shape(
	(ShapeType)Enum.Parse(typeof(ShapeType),
	((MenuItem)sender).Header.ToString()));

newShape.AutoSize = true;
newShape.Sizable = false;
newShape.Movable = false;

// add shape directly to TextControl
drawingObject.Shapes.Add(newShape, ShapeCollection.AddStyle.Fill);
[Visual Basic]
Dim drawingObject As New TXTextControl.WPF.Drawing.TXDrawingControl(5000, 5000)

' create a new DrawingFrame object that hosts the TXDrawingControl
Dim drawingFrame As New TXTextControl.DataVisualization.DrawingFrame(drawingObject)

' add the frame object to the Drawings collection
textControl1.Drawings.Add(drawingFrame, New System.Drawing.Point(0, 0), -1, TXTextControl.FrameInsertionMode.DisplaceText)

Dim newShape As New TXTextControl.Drawing.Shape(DirectCast([Enum].Parse(GetType(ShapeType), DirectCast(sender, MenuItem).Header.ToString()), ShapeType))

newShape.AutoSize = True
newShape.Sizable = False
newShape.Movable = False

' add shape directly to TextControl
drawingObject.Shapes.Add(newShape, ShapeCollection.AddStyle.Fill)