Inserting a drawings canvas

The second approach to insert shape objects into TX Text Control is a drawing canvas. This canvas is a DataVisualization.DrawingFrame object that hosts the WPF.Drawing.TXDrawingControl object, but the inserted shapes don't necessarily fit the complete frame.

The following code inserts the drawing canvas that fits exactly the page width without page margins:

[C#]
// calculate the available page width
textControl1.PageUnit = TXTextControl.MeasuringUnit.Twips;
int iPageWidth = (int)(textControl1.Sections.GetItem().Format.PageSize.Width -
	textControl1.Sections.GetItem().Format.PageMargins.Left -
	textControl1.Sections.GetItem().Format.PageMargins.Right);

// create a new TXDrawingControl that fills the complete page width
TXTextControl.WPF.Drawing.TXDrawingControl drawingObject =
	new TXTextControl.WPF.Drawing.TXDrawingControl(iPageWidth, 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, -1);
drawingFrame.Activate();
[Visual Basic]
' calculate the available page width
textControl1.PageUnit = TXTextControl.MeasuringUnit.Twips
Dim iPageWidth As Integer = CInt(textControl1.Sections.GetItem().Format.PageSize.Width - textControl1.Sections.GetItem().Format.PageMargins.Left - textControl1.Sections.GetItem().Format.PageMargins.Right)

' create a new TXDrawingControl that fills the complete page width
Dim drawingObject As New TXTextControl.WPF.Drawing.TXDrawingControl(iPageWidth, 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, -1)
drawingFrame.Activate()

When clicking a shape name in the main menu Insert -> Shapes while the drawing canvas is active, the mouse can be used to draw the shape on the activated drawing canvas.

[C#]
// create new Shape object from selected menu item text string
TXTextControl.Drawing.Shape newShape = new TXTextControl.Drawing.Shape(
	(ShapeType)Enum.Parse(typeof(ShapeType), ((MenuItem)sender).Header.ToString()));

// add Shape object to drawing canvas
((TXTextControl.WPF.Drawing.TXDrawingControl)
 textControl1.Drawings.GetActivatedItem().Drawing)
	.Shapes.Add(newShape, ShapeCollection.AddStyle.MouseCreation);
[Visual Basic]
' create new Shape object from selected menu item text string
Dim newShape As New TXTextControl.Drawing.Shape(DirectCast([Enum].Parse(GetType(ShapeType), DirectCast(sender, MenuItem).Header.ToString()), ShapeType))

' add Shape object to drawing canvas
DirectCast(textControl1.Drawings.GetActivatedItem().Drawing, TXTextControl.WPF.Drawing.TXDrawingControl).Shapes.Add(newShape, ShapeCollection.AddStyle.MouseCreation)