# Creating a Simple Word Processor

> Build a Visual Basic 6 word processor: place TXTextControl, button bar, rulers and status bar on a form, connect them and add Format, Edit and File menus.

- **Product:** TX Text Control ActiveX
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control ActiveX > Getting Started > Creating a Simple Word Processor
- **3101 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-activex/getting-started/first-application/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-activex/getting-started/first-application/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-activex/getting-started/first-application/llms-full.txt

---

A small word processor built with TX Text Control ActiveX and Visual Basic 6 takes only a few lines of code. Starting from an empty project, you place a `TXTextControl`, a `TXButtonBar`, two `TXRulerBar` controls and a `TXStatusBar` on a form, connect them and add a menu. The finished program loads and saves files, uses the clipboard, opens dialog boxes for character and paragraph formatting and has a ruler bar, a status bar and a full keyboard and mouse interface.

The source code of this example is in the *Samples\\vb6\\Simple* sample source directory.

### Create the Project

Before you start, run the TX Text Control installation program and start Visual Basic. Then create a project for the word processor:

1. Select the **New Project** command from the **File** menu.
2. Use the **Project / Components...** command to add the file *tx4ole34.ocx* to the new project.

Four additional icons appear at the bottom of the toolbox. They represent `TXTextControl` and its status bar, button bar and ruler bar:

![Toolbox icon of the TXTextControl control](https://docs.textcontrol.com/assets/img/tx-text-control-activex/toolbox-icon-textcontrol.697fea2b.webp)

The `TXTextControl` icon

![Toolbox icon of the TXStatusBar control](https://docs.textcontrol.com/assets/img/tx-text-control-activex/toolbox-icon-statusbar.c5520938.webp)

The `TXStatusBar` icon

![Toolbox icon of the TXButtonBar control](https://docs.textcontrol.com/assets/img/tx-text-control-activex/toolbox-icon-buttonbar.5a6d8bcc.webp)

The `TXButtonBar` icon

![Toolbox icon of the TXRulerBar control](https://docs.textcontrol.com/assets/img/tx-text-control-activex/toolbox-icon-rulerbar.0ad33e51.webp)

The `TXRulerBar` icon

### Place the Controls on the Form

Put the four controls on a form. Click the `TXTextControl` icon and draw the control on the form. In the same way, create a button bar, two ruler bars and a status bar.

Position the toolbars with the **Align** property:

- **Button bar and first ruler bar.** Set **Align** to **1 - Align Top**.
- **Status bar.** Set **Align** to **2 - Align Bottom**.
- **Second ruler bar.** Set its [Direction](https://docs.textcontrol.com/tx-text-control-activex/reference/txrulerbar/direction-property/llms-full.txt) property to **1 - Vertical** and align it to the left by setting **Align** to **3 - Align Left**.

These settings arrange everything except the width and the height of `TXTextControl`, which you set in [Resize the Text Control](#resize-the-text-control). Your form now looks like this:

![Visual Basic form in design mode with a button bar and a horizontal ruler at the top, a vertical ruler on the left, a status bar at the bottom and a TXTextControl in the middle](https://docs.textcontrol.com/assets/img/tx-text-control-activex/form-controls-design-mode.b378a5ab.webp)

### Connect the Controls

Add the following code to the form's `Load` event procedure:

```vbscript
Private Sub Form_Load()
   TXTextControl1.ButtonBarHandle = TXButtonBar1.hWnd
   TXTextControl1.RulerHandle = TXRuler1.hWnd
   TXTextControl1.VerticalRulerHandle = TXRuler2.hWnd
   TXTextControl1.StatusBarHandle = TXStatusBar1.hWnd
End Sub
```

The code works as follows:

- [ButtonBarHandle](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/buttonbarhandle-property/llms-full.txt) specifies the button bar that `TXTextControl1` uses, by the window handle that the [hWnd](https://docs.textcontrol.com/tx-text-control-activex/reference/txbuttonbar/hwnd-property/llms-full.txt) property of `TXButtonBar1` returns.
- [RulerHandle](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/rulerhandle-property/llms-full.txt) connects the horizontal ruler bar `TXRuler1`, and [VerticalRulerHandle](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/verticalrulerhandle-property/llms-full.txt) the vertical ruler bar `TXRuler2`.
- [StatusBarHandle](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/statusbarhandle-property/llms-full.txt) connects the status bar `TXStatusBar1`.

### Run the Program

The word processor isn't finished yet, but you can run it and see what it does. Click the **Start** button. You can type text, select it with the mouse, copy it to the clipboard and paste it (with CTRL+C and CTRL+V, as long as there is no menu), select a different font, set tabs and do much more. All of these features are built into `TXTextControl` and need almost no programming.

Some features are still missing:

- When you resize the main window, `TXTextControl` keeps its old size.
- There is no menu.
- There is no horizontal scroll bar.

The following steps add them.

### Set the Page View

TX Text Control offers several view modes for different tasks. To work as a word processor, set the [ViewMode](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/viewmode-property/llms-full.txt) property to **Page View** in the Properties window. This automatically adds the horizontal scroll bar, the page size and the margins.

![Properties window of TXTextControl1 in Visual Basic, where the ViewMode property is set](https://docs.textcontrol.com/assets/img/tx-text-control-activex/properties-window-viewmode.8d88c15a.webp)

You can also choose the view mode on the **Page** tab of the control's property pages:

![Visual Basic 6 form in design mode with a button bar, a ruler bar, TXTextControl1 and a status bar, and the Property Pages dialog box of TXTextControl1 open on the Page tab with the ViewMode list showing 2 - Page View, 3 - Floating Text and 4 - Simple Control](https://docs.textcontrol.com/assets/img/tx-text-control-activex/property-pages-view-mode.2cbcbe1b.webp)

### Resize the Text Control

To make `TXTextControl` resize with the main window, handle the form's `Resize` event:

1. Open the code window of the form that contains `TXTextControl`.
2. In the combo boxes at the top of the code window, select **Form** in the **Object:** box and **Resize** in the **Proc:** box.

The code window shows an empty procedure for the `Resize` event:

```vbscript
Private Sub Form_Resize ()
End Sub
```

Extend it as follows:

```vbscript
Private Sub Form_Resize ()
   If WindowState <> 1 Then
      TXTextControl1.Left = TXRuler2.Width
      TXTextControl1.Top = TXButtonBar1.Height + TXRuler1.Height
      TXTextControl1.Height = ScaleHeight - TXButtonBar1.Height _
         - TXRuler1.Height - TXStatusBar1.Height
      TXTextControl1.Width = ScaleWidth - TXRuler2.Width
   End If
End Sub
```

The code works as follows:

- Every time the size of the form changes, the position, width and height of `TXTextControl1` are adjusted. While the form is minimized (`WindowState` 1), the procedure changes nothing.
- `Left` and `Top` place the control to the right of the vertical ruler bar and below the button bar and the horizontal ruler bar.
- `Height` and `Width` fill the rest of the form's `ScaleHeight` and `ScaleWidth`, leaving room for the bars.
- The `_` character continues one logical line of code on the next physical line.

### Add a Menu

A menu gives the word processor access to the built-in dialog boxes of `TXTextControl`, the clipboard and files. You create the menus with the Visual Basic Menu Design Window; the Visual Basic documentation describes how to create menus.

![Visual Basic Menu Editor with the File, Edit and Format menus and the item mnuFormat_Paragraph selected](https://docs.textcontrol.com/assets/img/tx-text-control-activex/menu-editor.f749e3f7.webp)

#### Format Menu

Create a **Format** menu with the items **Character...** and **Paragraph...**. Name the items `mnuFormat_Character` and `mnuFormat_Paragraph`, and add the following code to their `Click` procedures:

```vbscript
Private Sub mnuFormat_Character_Click()
   TXTextControl1.FontDialog
End Sub
Private Sub mnuFormat_Paragraph_Click()
   TXTextControl1.ParagraphDialog
End Sub
```

[FontDialog](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/fontdialog-method/llms-full.txt) opens the built-in font dialog box, and [ParagraphDialog](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/paragraphdialog-method/llms-full.txt) the built-in paragraph dialog box. Start the program again: the menu items now open the **Font** and **Paragraph** dialog boxes.

![The built-in Font dialog box with font, size, attributes, position, underlining and text and background colors, opened in the TXWords sample, in the look of TX Text Control 10](https://docs.textcontrol.com/assets/img/tx-text-control-activex/font-dialog.9542989b.webp)

#### Edit Menu

In the Menu Design Window, create an **Edit** menu with the items **Cut**, **Copy** and **Paste**. The code for these menu items is:

```vbscript
Private Sub mnuEdit_Cut_Click()
   TXTextControl1.Clip 1
End Sub
Private Sub mnuEdit_Copy_Click()
   TXTextControl1.Clip 2
End Sub
Private Sub mnuEdit_Paste_Click()
   TXTextControl1.Clip 3
End Sub
```

The [Clip](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/clip-method/llms-full.txt) method cuts the selection to the clipboard with 1, copies it with 2 and pastes the clipboard's contents with 3. With these menu items, you can exchange formatted text with other word processors through the clipboard.

#### File Menu

The last menu is a simple **File** menu:

1. Create a **File** menu with the items **Load...** and **Save As...**.
2. Place a common dialog box icon on the form.

Then add the following code. It opens the common dialog box to get a file name from the user and then loads or saves the selected file:

```vbscript
Private Sub mnuFile_Load_Click()
   On Error Resume Next
   ' Create an "Open File" dialog box
   CommonDialog1.Filter = "TX Demo (*.tx)|*.tx"
   CommonDialog1.DialogTitle = "Open"
   CommonDialog1.Flags = cdlOFNFileMustExist Or _
      cdlOFNHideReadOnly
   CommonDialog1.CancelError = True
   CommonDialog1.ShowOpen
   If Err Then Exit Sub
   ' Pass the filename to the Text Control
   TXTextControl1.Load CommonDialog1.filename, 0
End Sub
Private Sub mnuFile_SaveAs_Click()
   On Error Resume Next
   ' Create a "Save File" dialog box
   CommonDialog1.Filter = "TX Demo (*.tx)|*.tx"
   CommonDialog1.DialogTitle = "Save As"
   CommonDialog1.Flags = cdlOFNOverwritePrompt Or _
      cdlOFNHideReadOnly
   CommonDialog1.CancelError = True
   CommonDialog1.ShowSave
   If Err Then Exit Sub
   ' Open the selected file
   TXTextControl1.Save CommonDialog1.filename, 0
End Sub
```

The code works as follows:

- `CommonDialog1` shows an **Open** or a **Save As** dialog box for files with the extension *.tx*. Because `CancelError` is `True`, canceling the dialog box raises an error, and `If Err Then Exit Sub` leaves the procedure.
- [Load](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/load-method/llms-full.txt) and [Save](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/save-method/llms-full.txt) read and write the selected file. The second parameter is the file offset, 0; without a format parameter, both methods use the internal Text Control format.

The *Simple* sample of version 34.0 goes one step further: its **Load...** and **Save as...** items offer RTF, DOC, DOCX, HTML and the TX format in the dialog box and pass the matching format value to `Load` and `Save`, for example 5 for RTF and 13 for DOCX. [Working with Files](https://docs.textcontrol.com/tx-text-control-activex/document-editor/load-save/llms-full.txt) describes the formats.

### Next Steps

TX Text Control has many more features than this small program uses. Zoom, images, tables, OLE objects, paragraph frames and whatever else a full word processor needs are up to you. For hints on integrating special features, look at the source code of the other sample programs, or post a message in the Text Control support forum on [www.textcontrol.com](https://www.textcontrol.com).

- [Working with Files](https://docs.textcontrol.com/tx-text-control-activex/document-editor/load-save/llms-full.txt): the file formats and how to choose one when loading and saving.
- [A Word Processor](https://docs.textcontrol.com/tx-text-control-activex/document-editor/word-processor/llms-full.txt): the TXWords sample with page setup, printing, search and color dialog boxes.
- [Text Formatting and Views](https://docs.textcontrol.com/tx-text-control-activex/document-editor/viewing/llms-full.txt): view modes and the coordinate system.
- [How to Obtain Support](https://docs.textcontrol.com/tx-text-control-activex/overview/support/llms-full.txt): the ways to reach Text Control support.

---

## Nearby

- **Previous:** [Getting Started](https://docs.textcontrol.com/tx-text-control-activex/getting-started/llms-full.txt)
- **Next:** [Document Editor](https://docs.textcontrol.com/tx-text-control-activex/document-editor/llms-full.txt)
