Printing Labels

Windows Forms User's Guide > Howto: Use Text Frames

This sample program shows how to insert multiple text frames simultaneously. The application is a label printing program, used to print, for instance, address labels or badges. The source code for this sample program can be found in the TextFrames\Printing Address Labels directory.

The sample program contains a dialog box for entering information about the label sheet to be used, e.g. the number of labels and their dimensions.

The program then creates a text frame for each of the labels.

The text frames can them be filled out, either manually by clicking on a field and typing in text, or from a file or database. When you click on the Fill in menu item, the sample program will enter the words "Address no." followed by the field identifier into each of the frames.

To load text from a file instead, simply replace the Selection.Text property with a call to the Selection.Load method.

private void mnuLabel_FillIn_Click(object sender, System.EventArgs e)
    int n = 0;
    foreach (TXTextControl.TextFrame frame in textControl1.TextFrames) 
        frame.Selection.Text = "Text Frame #" + Convert.ToString(n++);
[Visual Basic]
Private Sub mnuLabel_FillIn_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuLabel_FillIn.Click
    Dim N As Integer

    For Each Frame As TXTextControl.TextFrame In TextControl1.TextFrames
        Frame.Selection.Text = "Text Frame #" & N
        N = N + 1
End Sub