TX Text Control ActiveX

Using Text Frames

Topic

A text frame is a rectangle in the document that holds text of its own, apart from the main text. With text frames you place and handle text independently: a data entry field inside a line, a box that the main text flows around, or a sheet of address labels.

Two Visual Basic 6 samples from the Samples\vb6\TextFrames folder show the work: the first inserts a single text frame and opens its settings, the second fills a page with text frames for printing labels.

How Text Frames Are Placed

TX Text Control has three methods for inserting text frames:

MethodPlacementTypical use
TextFrameInsertAnchored to a paragraph. Text can flow around the frame, and the frame moves with the paragraph.The default method for inserting text frames
TextFrameInsertAsCharHandled like a single character in the textSmall data entry fields
TextFrameInsertFixedAt a fixed position on the page. The frame keeps its position regardless of changes to the surrounding text.Frames that must not move with the text

Two overlapping text frames with colored backgrounds in a TXTextControl of version 34.0, with the main text flowing around them.

Insert a Text Frame

The first sample program inserts a text frame with TextFrameInsert. Its source code is in the Samples\vb6\TextFrames\Inserting Text Frames folder. The program has two menu items: one calls TextFrameInsert to create a text frame, and the other calls ObjectAttrDialog to open a settings dialog box.

Private Sub mnuTextFrame_Insert_Click()
    TXTextControl1.TextFrameInsert -1, 0, 0, 0, 1000, 1000, 3, 20, 20, 20, 20
End Sub

Private Sub mnuTextFrame_Settings_Click()
    TXTextControl1.ObjectAttrDialog
End Sub

The code works as follows:

  • TextFrameInsert anchors the frame to the paragraph at the current input position (-1), positions it horizontally by PosX (alignment 0) at the position 0, 0 relative to the paragraph, makes it 1000 twips wide and high, lets the text flow around it (3) and keeps a distance of 20 twips to the text on each side.
  • ObjectAttrDialog opens the settings dialog box of the selected object.

The user moves and resizes text frames by dragging them with the mouse. A click on the border of a text frame selects and activates it. Once a text frame is selected, the Settings menu item opens its settings dialog box.

Enable the Settings Only for a Selected Frame

ObjectAttrDialog works with all types of insertable objects, including text frames, images and OLE objects. So that the dialog box does not open when no text frame is selected, the sample enables the Settings menu item only after a text frame has been clicked. The mnuTextFrame_Click event handler does this:

Private Sub mnuTextFrame_Click()
    mnuTextFrame_Settings.Enabled = (TXTextControl1.ObjectGetSelected(&H20) <> 0)
End Sub

The code works as follows:

  • ObjectGetSelected is another method that works with all insertable objects. Its parameter determines which type of object it looks for, here &H20 for text frames. It returns zero when no such object is selected.

Find the Members for Text Frames

The programming category Images, Text Frames, Signature Fields and OLE Objects lists all properties, methods and events for text frames. Members whose names begin with "Object" work with text frames and with the other kinds of embedded objects, such as images and OLE objects. Members whose names begin with "TextFrame" apply to text frames only.

Next Steps