# Headers and Footers

> Add, activate and remove headers and footers with HeaderFooter, HeaderFooterActivate and HeaderFooterStyle, and change their text with HeaderFooterSelect.

- **Product:** TX Text Control ActiveX
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control ActiveX > Document Editor > Headers and Footers
- **2599 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-activex/document-editor/headers-footers/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-activex/document-editor/headers-footers/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-activex/document-editor/headers-footers/llms-full.txt

---

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.

### How Headers and Footers Work

Headers and footers are visible only when the [ViewMode](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/viewmode-property/llms-full.txt) property is set to **Page View**. [Text Formatting and Views](https://docs.textcontrol.com/tx-text-control-activex/document-editor/viewing/llms-full.txt) describes the view modes.

Headers and footers are parts of a document. The [HeaderFooter](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/headerfooter-property/llms-full.txt) property determines whether the document contains headers and footers, only headers or only footers. It also specifies a different header, footer or both for the first page and for even pages.

To edit a header or footer, it must be activated, either with the [HeaderFooterActivate](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/headerfooteractivate-method/llms-full.txt) method or by a double-click in the area of the header or footer:

- **The activated part.** An activated header or footer gets the input focus. Since version 19.0, a dividing line separates it from the main text, with a label that tells which type of header or footer (even, odd, first page) is activated.
- **The gray text.** While a header or footer is activated, the main text is displayed in gray. Otherwise, the text of the headers and footers is displayed in gray.
- **The events.** `TXTextControl` fires the [HeaderFooterActivated](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/headerfooteractivated-event/llms-full.txt) and [HeaderFooterDeactivated](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/headerfooterdeactivated-event/llms-full.txt) events to tell your application that a header or footer has been activated or deactivated.

### Set How Headers and Footers Are Activated

The [HeaderFooterStyle](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/headerfooterstyle-property/llms-full.txt) property offers these settings:

- **Activation.** A header or footer is activated with double-clicks, single clicks or both.
- **Border.** An activated header or footer is divided from the main text by a dashed line, or has a solid border or no border.

By default, a header or footer is activated with a double-click and divided from the main text by a dashed line. Set `HeaderFooterStyle` to `txMouseClick` to let users activate headers and footers with a single click as well.

### Position Headers and Footers

By default, the top of a header is one centimeter from the top of the page, and the bottom of a footer is one centimeter from the bottom of the page. The [HeaderFooterPosition](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/headerfooterposition-property/llms-full.txt) property changes these distances. The height of a header or footer depends on its current text.

When a document is loaded or converted from another format, the headers and footers it contains are displayed automatically. The `HeaderFooter` property returns which headers and footers the current document contains.

### Program Headers and Footers

Headers and footers are separate text parts, independent of the main text. When the user changes the text or its format, for example with a connected `TXButtonBar`, `TXTextControl` uses the current input focus to decide whether the change applies to a header, a footer or the main text. The same happens when your code changes the text. When a menu inserts a table with the [TableInsert](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/tableinsert-method/llms-full.txt) method, for example, the input focus decides whether the table goes into a header, a footer or the main text.

Instead of relying on this default, your code can call the [HeaderFooterSelect](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/headerfooterselect-method/llms-full.txt) method to make a property or method work on a certain text part. The following code changes the text of the header:

```vbscript
TXTextControl1.HeaderFooterSelect txHeader
TXTextControl1.Text = "This is the header's text"
TXTextControl1.HeaderFooterSelect 0
```

The code works as follows:

- The first line selects the header, regardless of the current input focus.
- The second line changes the text of the header with the [Text](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/text-property/llms-full.txt) property.
- The third line returns to the default selection mode.

Between the two `HeaderFooterSelect` calls, you can use more than one property or method.

#### Members That Work With Headers and Footers

Almost all properties and methods work this way, with some exceptions. This is the complete list of properties and methods that work with headers and footers:

- all properties and methods for [character formatting](https://docs.textcontrol.com/tx-text-control-activex/reference/categories/character-formatting/llms-full.txt)
- all properties and methods for [paragraph formatting](https://docs.textcontrol.com/tx-text-control-activex/reference/categories/paragraph-formatting/llms-full.txt)
- all properties and methods for [marked text fields](https://docs.textcontrol.com/tx-text-control-activex/reference/categories/text-fields/llms-full.txt)
- all properties and methods for [hypertext links](https://docs.textcontrol.com/tx-text-control-activex/reference/categories/hypertext-links/llms-full.txt)
- all properties and methods for [tables](https://docs.textcontrol.com/tx-text-control-activex/reference/categories/tables/llms-full.txt)
- all properties and methods for [images, text frames and objects](https://docs.textcontrol.com/tx-text-control-activex/reference/categories/images-objects/llms-full.txt)
- the [CurrentInputPosition](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/currentinputposition-property/llms-full.txt) property
- the [Find](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/find-method/llms-full.txt) method
- the [FindReplace](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/findreplace-method/llms-full.txt) method
- the [FormatSelection](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/formatselection-property/llms-full.txt) property
- the [RTFSelText](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/rtfseltext-property/llms-full.txt) property
- the [SelLength](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/sellength-property/llms-full.txt) property
- the [SelStart](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/selstart-property/llms-full.txt) property
- the [SelText](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/seltext-property/llms-full.txt) property
- the [TabKey](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/tabkey-property/llms-full.txt) property
- the [Text](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/text-property/llms-full.txt) property

#### Members That Need HeaderFooterSelect

The following members work on a header or footer only in combination with the `HeaderFooterSelect` method:

- the [Load](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/load-method/llms-full.txt) method
- the [LoadFromMemory](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/loadfrommemory-method/llms-full.txt) method
- the [LoadSaveAttribute](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/loadsaveattribute-property/llms-full.txt) property
- the [Save](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/save-method/llms-full.txt) method
- the [SaveToMemory](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/savetomemory-method/llms-full.txt) method
- the [SaveToMemoryBuffer](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/savetomemorybuffer-method/llms-full.txt) method

### 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.

![The Header/Footer example window with File and Insert menus, a button bar and a ruler, showing an activated first page header with a dotted frame.](https://docs.textcontrol.com/assets/img/tx-text-control-activex/header-first-page-dotted.b14c1f09.webp)

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:

```vbscript
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:

```vbscript
TXTextControl1.HeaderFooterSelect txHeader
TXTextControl1.SelText = "Header"
TXTextControl1.HeaderFooterSelect 0
```

The code works as follows:

- `HeaderFooterSelect txHeader` selects the header, so that the following code affects the header.
- The [SelText](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/seltext-property/llms-full.txt) property sets the text of the header.
- `HeaderFooterSelect 0` resets 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:

```vbscript
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](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/headerfooteractivate-method/llms-full.txt) 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](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/headerfooter-property/llms-full.txt) | Determines which headers and footers the document contains, including those for the first page. |
| [HeaderFooterActivate](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/headerfooteractivate-method/llms-full.txt) | Activates a header or footer for editing. |
| [HeaderFooterActivated](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/headerfooteractivated-event/llms-full.txt), [HeaderFooterDeactivated](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/headerfooterdeactivated-event/llms-full.txt) | Occur when a header or footer is activated or deactivated. |
| [HeaderFooterSelect](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/headerfooterselect-method/llms-full.txt) | Makes properties and methods work on a header, a footer or the main text. |
| [HeaderFooterStyle](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/headerfooterstyle-property/llms-full.txt) | Sets how headers and footers are activated and how their border looks. |
| [HeaderFooterPosition](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/headerfooterposition-property/llms-full.txt) | Sets the distance of headers and footers from the page edges. |

The programming category [Headers and Footers](https://docs.textcontrol.com/tx-text-control-activex/reference/categories/headers-footers/llms-full.txt) lists all properties, methods and events for headers and footers.

### Related Pages

- [Text Formatting and Views](https://docs.textcontrol.com/tx-text-control-activex/document-editor/viewing/llms-full.txt): the page view, which shows headers and footers.
- [Tables](https://docs.textcontrol.com/tx-text-control-activex/document-editor/tables/llms-full.txt): tables, which also work inside headers and footers.
- [Headers and Footers](https://docs.textcontrol.com/tx-text-control-activex/reference/categories/headers-footers/llms-full.txt): all members for headers and footers.

---

## Nearby

- **Previous:** [Using Text Frames](https://docs.textcontrol.com/tx-text-control-activex/document-editor/text-frames/llms-full.txt)
- **Next:** [Marked Text Fields](https://docs.textcontrol.com/tx-text-control-activex/document-editor/fields/llms-full.txt)
