Headers and Footers

Visual Basic User's Guide

This example shows how to use headers and footers. The source code is contained in the Samples\vb6\Headers sample source directory.

TX supports headers as well as footers. You also have the ability to create a different header or footer for the first page.

The Sample Program

To insert a header or footer in the example, click on Insert and choose one of the four possible options. The code that is executed when clicking on one of the menu items is almost the same. For the Header menu item it looks as shown below. The line

[Visual Basic 6]
TXTextControl1.HeaderFooter = TXTextControl1.HeaderFooter + txHeader

informs Text Control that a header should be added to the current settings.

Setting the HeaderFooterStyle property to txMouseClick enables the user to activate the header with a single click rather than a double-click. Activating a header or footer with a double-click is Text Control's default setting. More information about how to use headers and footers and a list of all properties, methods and events that can be used with headers and footers, can be found in the in the chapter Technical Articles - Headers and Footers.

When using properties, Text Control distinguishes between the main text and headers or footers. To switch between these different independent text parts, Text Control provides the HeaderFooterSelect method:

[Visual Basic 6]
TXTextControl1.HeaderFooterSelect txHeader
TXTextControl1.SelText = "Header"
TXTextControl1.HeaderFooterSelect 0

This code selects the header, so that the following code affects the header and then sets the headers text. Finally the mode is reset to zero using the HeaderFooterSelect method. More information about programming with headers and footers see the chapter Technical Articles - Headers and Footers - Programming Headers and Footers.

A header or footer is activated from programming code using the HeaderFooterActivate method. To delete a header or footer, simply subtract the txHeader constant from the current HeaderFooter settings.The following is the complete code of the menu item:

[Visual Basic 6]
Private Sub mnuHeader_Click()
   If mnuHeader.Checked = False Then
      TXTextControl1.HeaderFooter = _
         TXTextControl1.HeaderFooter + txHeader
      TXTextControl1.HeaderFooterSelect txHeader
      TXTextControl1.SelText = "Header"
      TXTextControl1.HeaderFooterSelect 0
      TXTextControl1.HeaderFooterActivate txHeader
      mnuHeader.Checked = True
   Else
      TXTextControl1.HeaderFooter = _
         TXTextControl1.HeaderFooter - txHeader
      mnuHeader.Checked = False
   End If
End Sub