TX Text Control ActiveX

Button Bar, Ruler Bar and Status Bar

Topic

Word processor users expect a strip of formatting buttons above the text, a ruler for indents and tabs and a status line that tells them where they are. TX Text Control ActiveX ships all three as separate controls in the same OCX file as TXTextControl: TXButtonBar, TXRulerBar and TXStatusBar. Once you connect them, they show the attributes at the input position and change them without any further code.

The sections below describe what each bar shows, how to connect it, how to arrange its buttons and fields and how the TXWords sample sets them up and hides them. To place the controls on a form for the first time, follow Creating a Simple Word Processor.

What the Three Bars Show

The screenshots show version 34.0. In the main window of TXWords, the button bar sits below the menu and the sample's own toolbar, the horizontal ruler below it, the vertical ruler on the left and the status bar at the bottom:

The main window of the TXWords sample of TX Text Control ActiveX version 34.0 with the TXButtonBar, the horizontal and vertical TXRulerBar controls, a TXTextControl in page view and the TXStatusBar.

TXButtonBar

A TXButtonBar offers combo boxes and buttons for the formatting of the selected text: the formatting style, the font name and size, bold, italic and underline, paragraph alignment, lists, tabs and a zoom box. It always shows the attributes of the current selection, so a user sees at a glance which font and alignment the text has.

The TXButtonBar of TXWords in version 34.0 with the style, font and size combo boxes, the bold, italic, underline and font size buttons, the alignment and text direction buttons, the zoom box and the list, indent and tab buttons.

TXRulerBar

A TXRulerBar sets paragraph attributes such as indents and tab stops with the mouse, and the horizontal alignment of table cells. Its Direction property decides whether it is a horizontal ruler (0 - txHorizontal, the default) or a vertical ruler (1 - txVertical). An application that wants both uses two TXRulerBar controls.

The horizontal TXRulerBar of TX Text Control ActiveX version 34.0 with its scale, indent markers and tab type button.

When the input position is in a table, the ruler shows markers at the cell boundaries:

The horizontal TXRulerBar of TX Text Control ActiveX version 34.0 while the input position is in a table, with gray markers at the cell boundaries.

The input position is the place in the text where typed characters appear, marked by the blinking cursor. Selections, Clipboard and Undo explains it in detail.

TXStatusBar

A TXStatusBar shows the section, page, line and column number of the input position, the number of sections and pages, the language of the selected text and the zoom factor. It can also display an info text of your own, which you set with its Text property.

The TXStatusBar of TX Text Control ActiveX version 34.0 showing Section 1/5, Page 1/5, Line 1, Col 0, English (United States) and a zoom track bar at 100%.

Connect the Bars to TXTextControl

A bar on a form does nothing until TXTextControl knows about it. Four properties of TXTextControl take the window handle of a bar, which the bar's hWnd property returns:

Property of TXTextControlConnects
ButtonBarHandleA TXButtonBar
RulerHandleA TXRulerBar as the horizontal ruler
VerticalRulerHandleA TXRulerBar as the vertical ruler (since version 13.0)
StatusBarHandleA TXStatusBar

All four are run-time only: you can't set them in the Properties window, so you assign them in code, usually when the form loads. TXWords names its controls TXButtonBar1, TXRuler1 (horizontal), TXRuler2 (vertical) and TXStatusBar1, and connects them in a procedure that Form_Load calls:

Private Sub setWindowLayout(rtl As Boolean)
    TXTextControl1.RightToLeft = rtl
    TXRuler1.RightToLeft = rtl
    TXRuler2.RightToLeft = rtl
    TXButtonBar1.RightToLeft = rtl
    TXStatusBar1.RightToLeft = rtl

    ' Connect to rulers, button bar and status bar
    TXTextControl1.RulerHandle = TXRuler1.hwnd
    TXTextControl1.VerticalRulerHandle = TXRuler2.hwnd
    TXTextControl1.ButtonBarHandle = TXButtonBar1.hwnd
    TXTextControl1.StatusBarHandle = TXStatusBar1.hwnd
End Sub

The code works as follows:

  • The RightToLeft properties of TXRulerBar, TXButtonBar and TXStatusBar mirror the bars for right-to-left languages. TXWords passes True when the Windows reading direction is right to left.
  • Setting RightToLeft at run time recreates the bar's window, and the new window must be assigned to TXTextControl again. This is why TXWords connects the bars after it has set the direction, and again every time the user changes View > Window Layout.
  • Each ...Handle property receives the hWnd of one bar, for example hWnd of TXRuler1.

You don't have to use all four bars. Connect only the ones on your form.

Connect the Bars in Microsoft Access

In a Microsoft Access form, the ConnectTools event of TXTextControl occurs after all text controls and bars have been created and are ready to be connected. The reference describes two steps: set each handle property to 1 in the form's Load event, then assign the real hWnd values in the ConnectTools event procedure.

Arrange the Buttons of the Button Bar

Each element of the button bar has a Pos... property, such as PosFontBold or PosZoom. Its value is the element's position number, starting at 1:

  • 0 hides the element.
  • Adding 1000 to a position number creates a gap between the element and the element before it.
  • Adding 2000 creates a gap with a vertical group mark.

By default, the bar shows the style, font name and size boxes, bold, italic, underline, the four alignment buttons, the numbered, bulleted and structured list buttons, the tab type button and the control characters button. Strikethrough, subscript, superscript, the grow and shrink font buttons, the indent buttons, the text direction buttons, the four single tab buttons, the XML combo boxes and the zoom box are hidden until you give them a position. The PosControlChars page lists which property belongs to which element.

TXWords sets the positions at design time in the Properties window, where Visual Basic stores them in frmMain.frm:

PositionElementPropertyValue in TXWords
1Style boxPosStyle1
2, 3Font name and size boxesPosFontName, PosFontSize2, 3
4 to 6Bold, italic, underlinePosFontBold, PosFontItalic, PosFontUnderline2004, 5, 6
7, 8Grow and shrink fontPosGrowFont, PosShrinkFont7, 8
9 to 12Left, right, centered, justifiedPosParaLeft, PosParaRight, PosParaCentered, PosParaJustified2009, 10, 11, 12
13, 14Left to right, right to leftPosLeftToRight, PosRightToLeft2013, 14
15Zoom boxPosZoom2015
16 to 18Numbered, bulleted, structured listPosListNumbered, PosListBulleted, PosListStructured2016, 17, 18
19, 20Increase and decrease indentPosIncreaseIndent, PosDecreaseIndent19, 20
21Tab typePosTabSelect2021
22Control charactersPosControlChars22

The single tab buttons, strikethrough, subscript, superscript and the XML combo boxes have the value 0 and stay hidden.

The Pos... properties can also be set in code. To take the zoom box and the control characters button off the bar, set their positions to 0:

Private Sub Form_Load()
   ' Hide the zoom box and the control characters button
   TXButtonBar1.PosZoom = 0
   TXButtonBar1.PosControlChars = 0
   TXTextControl1.ButtonBarHandle = TXButtonBar1.hWnd
End Sub

To keep the button bar visible but stop it from changing the text, set its ReadOnly property to True (since version 24.0). It still shows the attributes of the selection.

Set Up the Rulers

The same TXRulerBar control serves as the horizontal and the vertical ruler. Its properties decide what it shows and what the user can change with it:

PropertyWhat it setsTXWords
Direction0 - txHorizontal or 1 - txVertical0 for TXRuler1, 1 for TXRuler2
ScaleUnitsThe scale: 0 for mm, 1 for cm, 2 for inch0
EnablePageMarginsWhether the user can set the page margins with the ruler (default True)True
FormulaModeWhether the ruler shows cell references in a table: 0 - rlNone, 1 - rlAuto (only in a cell that contains a formula) or 2 - rlAlways1
ReadOnlyShows the attributes but doesn't let the user change themFalse

FormulaMode shows the references in the A1 or the R1C1 notation, depending on the FormulaReferenceStyle property of TXTextControl, and has no effect when the ruler's Appearance is tx3D. Using Formulas in Table Cells describes formulas in table cells.

In TXWords, both rulers are aligned with the Visual Basic Align property: the horizontal ruler to the top, the vertical ruler to the left, or to the right when the window layout is right to left.

Choose the Status Bar Fields

Each field of the status bar has a Show... property that turns it on or off and, for the numbered fields, a Text... property with the label in front of the number:

FieldShown byLabelTXWords label
Section numberShowSectionTextSection"Section "
Number of sectionsShowSectionCounterTextSectionCounter"/"
Page numberShowPage, PageModeTextPage"Page "
Number of pagesShowPageCounterTextPageCounter"/"
Line numberShowLineTextLine"Line "
Column numberShowColumnTextColumn"Col "
Language of the selectionShowLocale----
Zoom factor as a track barShowZoomTrackBar----

TXWords sets all Show... properties to True, which gives the status bar in the screenshot above. ShowZoomTrackBar replaces the plain zoom number with a track bar that shows the zoom factor and lets the user set it.

PageMode controls the page field further: 0 hides it, 1 always shows it and 2 shows it only when the ViewMode of the connected TXTextControl is Page View. TXWords uses 2. Text Formatting and Views explains the view modes.

The labels are ordinary strings, so you can translate them. This code sets German labels and turns off the section fields:

Private Sub Form_Load()
   With TXStatusBar1
      .ShowSection = False
      .ShowSectionCounter = False
      .TextPage = "Seite "
      .TextPageCounter = " von "
      .TextLine = "Zeile "
      .TextColumn = "Spalte "
   End With
   TXTextControl1.StatusBarHandle = TXStatusBar1.hWnd
End Sub

Show and Hide the Bars

The View menu of TXWords has one item per bar: Tool Bar (the sample's own Windows toolbar), Button Bar, Horizontal Ruler, Vertical Ruler and Status Bar. A check mark shows which bars are visible.

The View menu of the TXWords sample of TX Text Control ActiveX version 34.0 with checked items for the Tool Bar, Button Bar, Horizontal Ruler, Vertical Ruler and Status Bar.

Each item switches the Visual Basic Visible property of its bar, toggles the check mark and resizes TXTextControl to fill the space. For the button bar, the code is:

Private Sub mnuView_ButtonBar_Click()
    ViewButtonBarProc
    mnuView_ButtonBar.Checked = Not mnuView_ButtonBar.Checked
End Sub

Sub ViewButtonBarProc()
    TXButtonBar1.Visible = Not TXButtonBar1.Visible
    Resize
End Sub

The Resize procedure of TXWords adds up the heights of the visible bars and of the sample's toolbar and the width of the vertical ruler, and sizes TXTextControl to the rest of the form. A hidden bar counts as 0. The rulers and the status bar work the same way with TXRuler1, TXRuler2 and TXStatusBar1. Creating a Simple Word Processor shows a simpler Form_Resize procedure for bars that are always visible.

Change the Look and the Language

All three bars have an Appearance property for their paint style, such as flat, 3D, Windows XP look or a color scheme that follows the system colors: TXButtonBar, TXRulerBar and TXStatusBar. The button bar has a second property, Style, for the paint style of its buttons. With the color scheme appearance, a DisplayColor property sets individual colors, for example of the TXRulerBar (since version 15.1). TXWords uses the color scheme for the rulers and the button bar, the Windows XP style for the buttons and the vertical color scheme (4 - sbVerticalColorScheme) for the status bar.

The bars display resources, such as the status bar texts and the images of the bold, italic and underline buttons, in a language of their own. Setting the language or the resource library of TXTextControl doesn't change them: set the Language or ResourceFile property of each bar, for example Language and ResourceFile of TXButtonBar. English and German are built in. Resources and Localization describes how TX Text Control chooses the language and how to build a resource library.

Key Members

MemberDescription
TXTextControl.ButtonBarHandleConnects a TXButtonBar to the text control.
TXTextControl.RulerHandleConnects a TXRulerBar as the horizontal ruler.
TXTextControl.VerticalRulerHandleConnects a TXRulerBar as the vertical ruler.
TXTextControl.StatusBarHandleConnects a TXStatusBar to the text control.
TXTextControl.ConnectToolsMicrosoft Access only: occurs when all controls can be connected.
TXButtonBar.PosControlCharsPosition of the control characters button, and the rules for all Pos... properties.
TXButtonBar.ReadOnlyShows the formatting without letting the user change it.
TXRulerBar.DirectionMakes a ruler horizontal or vertical.
TXRulerBar.ScaleUnitsThe scale of the ruler: mm, cm or inch.
TXRulerBar.FormulaModeShows cell references when the input position is in a table cell.
TXStatusBar.PageModeHides the page field, shows it always or only in page view.
TXStatusBar.ShowZoomTrackBarShows a track bar instead of a number for the zoom factor.
TXStatusBar.TextThe info text of the status bar.