Headers and Footers
Headers and footers repeat text such as a title, a company name or a page number at the top and the bottom of each page. In TXTextControl they are text parts of their own, separate from the main text: users activate them to type in them, and your code selects them to change their text and format.
The concept comes first: how headers and footers are shown, activated and positioned, and which properties and methods work on them. The Visual Basic 6 sample program of the Samples\vb6\Headers sample source directory then adds a header from a menu.
Run the Sample Program
The sample program of the Samples\vb6\Headers sample source directory adds headers and footers from a menu. TX Text Control supports headers and footers, and a different header or footer for the first page.

To insert a header or footer, click Insert and choose one of the four options. The code behind the menu items is almost the same for each of them; the sections below show it for the Header menu item.
Add a Header
This line tells TXTextControl to add a header to the current settings:
TXTextControl1.HeaderFooter = TXTextControl1.HeaderFooter + txHeader
HeaderFooter holds the sum of the headers and footers the document contains, so adding txHeader keeps the headers and footers that are already there.
Write the Header's Text
For its properties, TXTextControl distinguishes between the main text and the headers and footers. The HeaderFooterSelect method switches between these independent text parts:
TXTextControl1.HeaderFooterSelect txHeader
TXTextControl1.SelText = "Header"
TXTextControl1.HeaderFooterSelect 0
The code works as follows:
HeaderFooterSelect txHeaderselects the header, so that the following code affects the header.- The SelText property sets the text of the header.
HeaderFooterSelect 0resets the mode to zero.
Activate or Remove the Header
Your code activates a header or footer with the HeaderFooterActivate method. To delete a header, subtract the txHeader constant from the current HeaderFooter settings.
This is the complete code of the Header menu item:
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
The code works as follows:
- When the menu item is not checked, the procedure adds the header, writes "Header" into it, activates it with HeaderFooterActivate and checks the menu item.
- When the menu item is checked, the procedure removes the header and clears the check mark.
Key Members
| Member | Description |
|---|---|
| HeaderFooter | Determines which headers and footers the document contains, including those for the first page. |
| HeaderFooterActivate | Activates a header or footer for editing. |
| HeaderFooterActivated, HeaderFooterDeactivated | Occur when a header or footer is activated or deactivated. |
| HeaderFooterSelect | Makes properties and methods work on a header, a footer or the main text. |
| HeaderFooterStyle | Sets how headers and footers are activated and how their border looks. |
| HeaderFooterPosition | Sets the distance of headers and footers from the page edges. |
The programming category Headers and Footers lists all properties, methods and events for headers and footers.