Tutorial: Starting with Microsoft Visual Studio

Welcome to TX Text Control, the text processor in a single .NET control. Using TX Text Control, you can create all kinds of text-based applications with the ease of programming that is characteristic of development environments, such as Visual Studio .NET and with highly sophisticated formatting and display capabilities which are normally the exclusive domain of large word processing packages.

Creating the Project and Controls

Start Visual Studio .NET and create a new project. Select either Visual Basic or C# as a project type, and Windows Application as a template.

Image

Find the TX Text Control 29.0 toolbox tab that has been created automatically. All usable TX Text Control controls or components are listed in this tab.

Image

Click on the TextControl icon and draw it on the form.

Image

Now, click on the Smart Tag in the upper right corner of TextControl. In the Wizards group, click on Add a Button Bar, Add a Status Bar, Add a Ruler Bar and Add a Vertical Ruler. Finally, click on Arrange Controls Automatically. The controls are now connected and docked to fill the container:

Image

Build and start the application to see the first results.

Adding a Menu to the Project

In this chapter, we will add a menu to the text processor to enable you to call some of the built-in dialog boxes.

Image

Drag a Main Menu control on your form and create a File menu with the items Load... and Save....

Add the following code to the Click procedures of the menu items:

private void mnuFile_OpenFile_Click(object sender, System.EventArgs e)
{
    textControl1.Load(TXTextControl.StreamType.RichTextFormat | TXTextControl.StreamType.HTMLFormat);
}

private void mnuFile_SaveFileAs_Click(object sender, System.EventArgs e)
{
    textControl1.Save(TXTextControl.StreamType.RichTextFormat | TXTextControl.StreamType.HTMLFormat);
}
Private Sub mnuFile_OpenFile_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuFile_OpenFile.Click
    TextControl1.Load(TXTextControl.StreamType.RichTextFormat + TXTextControl.StreamType.HTMLFormat)
End Sub

Private Sub mnuFile_SaveFileAs_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuFile_SaveFileAs.Click
    TextControl1.Save(TXTextControl.StreamType.RichTextFormat + TXTextControl.StreamType.HTMLFormat)
End Sub

The Load and Save methods will automatically open a dialog box for the user to select a filename and file format, and then load, respectively save, the selected file.

Image

Now for the Edit menu. Create an Edit menu containing items for Cut, Copy and Paste. The code for these menu items is:

private void mnuCut_Click(object sender, System.EventArgs e)
{
    textControl1.Cut();
}

private void mnuCopy_Click(object sender, System.EventArgs e)
{
    textControl1.Copy();
}

private void mnuPaste_Click(object sender, System.EventArgs e)
{
    textControl1.Paste();
}
Private Sub mnuEdit_Cut_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuEdit_Cut.Click
    TextControl1.Cut()
End Sub

Private Sub mnuEdit_Copy_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuEdit_Copy.Click
    TextControl1.Copy()
End Sub

Private Sub mnuEdit_Paste_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuEdit_Paste.Click
    TextControl1.Paste()
End Sub

Having added these menu items, you can exchange formatted text with other word processors via the clipboard.

Now, create a Format menu with the items Character... and Paragraph.... Name the items mnuFomat_Character and mnuFormat_Paragraph and add the following code to their procedures.

private void mnuFormat_Character_Click(object sender, System.EventArgs e)
{
    textControl1.FontDialog();
}

private void mnuFormat_Paragraph_Click(object sender, System.EventArgs e)
{
    textControl1.ParagraphFormatDialog();
}
Private Sub mnuFormat_Character_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuFormat_Character.Click
    TextControl1.FontDialog()
End Sub

Private Sub mnuFormat_Paragraph_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuFormat_Paragraph.Click
    TextControl1.ParagraphFormatDialog()
End Sub