# Using Text Frames

> Insert text frames with TextFrameInsert, open their settings with ObjectAttrDialog and fill labels with ObjectNext and TextFrameSelect in Visual Basic 6.

- **Product:** TX Text Control ActiveX
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control ActiveX > Document Editor > Using Text Frames
- **1687 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-activex/document-editor/text-frames/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-activex/document-editor/text-frames/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-activex/document-editor/text-frames/llms-full.txt

---

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:

| Method | Placement | Typical use |
|---|---|---|
| [TextFrameInsert](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/textframeinsert-method/llms-full.txt) | Anchored to a paragraph. Text can flow around the frame, and the frame moves with the paragraph. | The default method for inserting text frames |
| [TextFrameInsertAsChar](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/textframeinsertaschar-method/llms-full.txt) | Handled like a single character in the text | Small data entry fields |
| [TextFrameInsertFixed](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/textframeinsertfixed-method/llms-full.txt) | At 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.](https://docs.textcontrol.com/assets/img/tx-text-control-activex/text-frames-document.403b0cd5.webp)

### 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](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/objectattrdialog-method/llms-full.txt) to open a settings dialog box.

```vbscript
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](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/textframeinsert-method/llms-full.txt) 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](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/objectattrdialog-method/llms-full.txt) 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:

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

The code works as follows:

- [ObjectGetSelected](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/objectgetselected-method/llms-full.txt) 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.

### Print Labels

The second sample program inserts many text frames at once. It is a label printing program for address labels or badges, for instance. Its source code is in the *Samples\\vb6\\TextFrames\\Printing Address Labels* directory.

The program has a dialog box, **Insert Label Group**, in which the user enters information about the label sheet, such as the number of labels and their dimensions:

![The Insert Label Group dialog box with the number of rows and columns, the label width and height, the page margins and the space between labels.](https://docs.textcontrol.com/assets/img/tx-text-control-activex/insert-label-group-dialog.9269e1cf.webp)

The program then creates a text frame for each label:

![The TX Text Control Label Printer sample in page view, with an empty text frame for each label arranged in rows and columns.](https://docs.textcontrol.com/assets/img/tx-text-control-activex/label-printer-frames.a92b9d2d.webp)

The text frames are filled out manually, when the user clicks a frame and types, or from a file or a database. The **Fill in** menu item enters the words "Address no." followed by the frame's identifier into each frame. In this sample, the `TXTextControl` is named `tx`:

```vbscript
Private Sub mnuLabel_FillIn_Click()
    Dim FrameID As Integer

    FrameID = tx.ObjectNext(0, &H20)
    While FrameID
        tx.TextFrameSelect (FrameID)
        tx.Text = "Address no. " & FrameID
        tx.TextFrameSelect 0
        FrameID = tx.ObjectNext(FrameID, &H20)
    Wend
End Sub
```

The code works as follows:

- [ObjectNext](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/objectnext-method/llms-full.txt) returns the identifier of the object that follows the given one. With `0`, it returns the first text frame (`&H20`), and it returns zero when there is no further frame, which ends the loop.
- [TextFrameSelect](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/textframeselect-method/llms-full.txt) with a frame's identifier makes the following properties work on that text frame. With `0`, it returns to the default mode, in which properties work on the text part with the current input position.
- [Text](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/text-property/llms-full.txt) sets the text of the selected frame. To load the text from a file instead, replace the `Text` property with a call to the [Load](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/load-method/llms-full.txt) method.

### Find the Members for Text Frames

The programming category [Images, Text Frames, Signature Fields and OLE Objects](https://docs.textcontrol.com/tx-text-control-activex/reference/categories/images-objects/llms-full.txt) 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

- [Using Images](https://docs.textcontrol.com/tx-text-control-activex/document-editor/images/llms-full.txt): inserting images, which share the "Object" members with text frames.
- [Printing](https://docs.textcontrol.com/tx-text-control-activex/document-editor/printing/llms-full.txt): printing the labels and other documents.
- [Images, Text Frames, Signature Fields and OLE Objects](https://docs.textcontrol.com/tx-text-control-activex/reference/categories/images-objects/llms-full.txt): all members for text frames and other objects.

---

## Nearby

- **Previous:** [Using Images](https://docs.textcontrol.com/tx-text-control-activex/document-editor/images/llms-full.txt)
- **Next:** [Headers and Footers](https://docs.textcontrol.com/tx-text-control-activex/document-editor/headers-footers/llms-full.txt)
