Products Technologies Demo Docs Blog Support Company

Inserting Shapes and Drawing Groups

TX Text Control provides a very powerful drawings feature to insert many different types of shapes into documents. This article shows how to add shapes and shape group containers to documents programmatically.

Inserting Shapes and Drawing Groups

TX Text Control provides a very powerful drawings feature to insert many different types of shapes into documents. The ribbon Insert tab provides an out-of-the-box UI to add shapes to a document:

TX Text Control shapes

Adding Single Shapes

In order to insert these shapes programmatically, several steps are required:

// create a drawing control that contains the shape(s)
TXTextControl.Drawing.TXDrawingControl drawing =
    new TXTextControl.Drawing.TXDrawingControl(3000, 3000);

// create a new donut shape
TXTextControl.Drawing.Shape shape =
    new TXTextControl.Drawing.Shape(TXTextControl.Drawing.ShapeType.Donut);

// set the color and border width
shape.ShapeFill.Color = Color.Red;
shape.ShapeOutline.Color = Color.Yellow;
shape.ShapeOutline.Width = 200;

// add the shape to the drawing control
drawing.Shapes.Add(
    shape, 
    TXTextControl.Drawing.ShapeCollection.AddStyle.Fill);

// create a new drawing frame object from the created drawing control
TXTextControl.DataVisualization.DrawingFrame frame = 
    new TXTextControl.DataVisualization.DrawingFrame(drawing);

// add the frame to the document
textControl1.Drawings.Add(frame, -1);

TX Text Control shapes

The above code inserts a shape at the current input position. If you want the user to "draw" the created shape onto the document, the following implementation of the DrawingCollection.Add method can be used:

textControl1.Drawings.Add(frame, TXTextControl.FrameInsertionMode.DisplaceText);

Adding Container Group Frames

The following code shows how to insert more shapes into a group frame. If the container group frame is moved, all contained shapes are moved together:

// create a drawing control that contains the shape(s)
TXTextControl.Drawing.TXDrawingControl drawingGroup =
    new TXTextControl.Drawing.TXDrawingControl(3000, 3000);

// create a new donut shape
TXTextControl.Drawing.Shape donut =
    new TXTextControl.Drawing.Shape(TXTextControl.Drawing.ShapeType.Donut) {
        Location = new Point(100, 100),
        Size = new Size(500,500)
    };

TXTextControl.Drawing.Shape diamond =
    new TXTextControl.Drawing.Shape(TXTextControl.Drawing.ShapeType.Diamond);

// add the shape to the drawing control
drawingGroup.Shapes.Add(donut);
drawingGroup.Shapes.Add(diamond);

// create a new drawing frame object from the created drawing control
TXTextControl.DataVisualization.DrawingFrame frame = 
    new TXTextControl.DataVisualization.DrawingFrame(drawingGroup);

// add the frame to the document
textControl1.Drawings.Add(
    frame, 
    textControl1.InputPosition.Location, 
    TXTextControl.FrameInsertionMode.DisplaceText);

The following screenshot shows the activated group container frame with the 2 inserted shapes:

TX Text Control shapes

Adding Additional Shapes to Containers

If the container frame is activated (dashed frame border), additional shapes can be added. The following code inserts a new shape into an activated container frame:

// create a new donut shape
TXTextControl.Drawing.Shape shape =
    new TXTextControl.Drawing.Shape(TXTextControl.Drawing.ShapeType.Donut);

// set the color and border width
shape.ShapeFill.Color = Color.Red;
shape.ShapeOutline.Color = Color.Yellow;
shape.ShapeOutline.Width = 200;

if (textControl1.Drawings.GetActivatedItem() != null)
{
    // add the shape to the drawing control
    ((TXDrawingControl)textControl1.Drawings.GetActivatedItem().Drawing).Shapes.Add(shape);
}

If you want the user to draw the additional shape into the container, the MouseCreation member must be used in the Shapes.Add method.

((TXDrawingControl)textControl1.Drawings.GetActivatedItem().Drawing).Shapes.Add(
  shape,
  ShapeCollection.AddStyle.MouseCreation);

TX Text Control shapes

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Also See

This post references the following in the documentation:

  • TXTextControl.DataVisualization.DrawingCollection.Add Method
  • TXTextControl.Drawing.ShapeCollection.Add Method
  • TXTextControl.Drawing.ShapeCollection.AddStyle Enumeration

Related Posts

ASP.NETWindows FormsWPF

TX Text Control 33.0 SP3 is Now Available: What's New in the Latest Version

TX Text Control 33.0 Service Pack 3 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…


ASP.NETWindows FormsWPF

TX Text Control 33.0 SP2 is Now Available: What's New in the Latest Version

TX Text Control 33.0 Service Pack 2 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…


ASP.NETWindows FormsWPF

Document Lifecycle Optimization: Leveraging TX Text Control's Internal Format

Maintaining the integrity and functionality of documents throughout their lifecycle is paramount. TX Text Control provides a robust ecosystem that focuses on preserving documents in their internal…


ActiveXASP.NETWindows Forms

Expert Implementation Services for Legacy System Modernization

We are happy to officially announce our partnership with Quality Bytes, a specialized integration company with extensive experience in modernizing legacy systems with TX Text Control technologies.


ActiveXASP.NETWindows Forms

Service Pack Releases: What's New in TX Text Control 33.0 SP1 and 32.0 SP5

TX Text Control 33.0 Service Pack 1 and TX Text Control 32.0 Service Pack 5 have been released, providing important updates and bug fixes across platforms. These service packs improve the…