Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.

Creating a Simple Word Processor in Delphi .NET

Topics for Wednesday, August 25 2004

Creating a Simple Word Processor in Delphi .NET

This article shows you how to integrate TX Text Control .NET into Delphi 8.0 .NET and above. It describes how to create a simple word processing application from scratch.

Creating the Project

After installing TX Text Control using the setup program, start Delphi .NET and create a new project. Select a Delphi for .NET Windows Forms application project.

Then use the Component / Installed .NET components dialog to add TX Text Control .NET to your tool palette. In the .NET Components tab, look for the four TX Text Control .NET components. If you sort the list by Namespace, you will see the 4 components:

  • TextControl
  • ButtonBar
  • RulerBar
  • StatusBar

Check them and click OK.

After closing the dialog, you will see the four TX Text Control .NET icons in the Tool Palette.

Creating the Controls

In this step, you put these controls on a form and connect them. Click on the ButtonBar icon and draw it on to the form. Do the same for the other three components. The form should now look like this:

Now set the Dock property to Top for the Button Bar and the Ruler Bar. TX Text Control should be set to Fill and the Status Bar to Bottom.

Connecting the Toolbars

At this stage, while you can type into TX Text Control, the button bar and the ruler bar cannot be used. They must be connected to TX Text Control in the form's Load event.

  1. procedure TWinForm.TWinForm_Load(sender: System.Object; e: System.EventArgs);
  2. begin
  3. TextControl1.ButtonBar := ButtonBar1;
  4. TextControl1.RulerBar := RulerBar1;
  5. TextControl1.StatusBar := StatusBar1;
  6. end;

Now start the application by pressing F9 and ensure that the toolbars are connected to TX Text Control.

Adding Menus

Now, we will add some menus to call the built-in dialog boxes of TX Text Control .NET.

Drag a MainMenu control on your form and create a Format menu with the items Character... and Paragraph.... Label the items mnuFomat_Character and mnuFormat_Paragraph. Add the following code to the Click procedures of the menu items:

  1. procedure TWinForm.mnuFormat_Paragraph_Click(sender: System.Object; e: System.EventArgs);
  2. begin
  3. TextControl1.ParagraphFormatDialog;
  4. end;
  5.  
  6. procedure TWinForm.mnuFormat_Character_Click(sender: System.Object; e: System.EventArgs);
  7. begin
  8. TextControl1.FontDialog;
  9. end;

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

  1. procedure TWinForm.mnuEdit_Paste_Click(sender: System.Object; e: System.EventArgs);
  2. begin
  3. TextControl1.Paste;
  4. end;
  5.  
  6. procedure TWinForm.mnuEdit_Copy_Click(sender: System.Object; e: System.EventArgs);
  7. begin
  8. TextControl1.Copy;
  9. end;
  10.  
  11. procedure TWinForm.MenuItem3_Click(sender: System.Object; e: System.EventArgs);
  12. begin
  13. TextControl1.Cut;
  14. end;

After adding these menu items, you will be able to cut, copy or paste text from other applications via the clipboard.

The last menu should implement a simple file menu. Create a File menu with the items Open File... and Save File As... and use the following code:

  1. procedure TWinForm.mnuFile_Save_Click(sender: System.Object; e: System.EventArgs);
  2. begin
  3. TextControl1.Save;
  4. end;
  5.  
  6. procedure TWinForm.mnuFile_Open_Click(sender: System.Object; e: System.EventArgs);
  7. begin
  8. TextControl1.Load;
  9. end;

The Load and Save methods are called without any parameters, so that they automatically open a dialog box for the end user to select the filename and the format. After clicking Open in the dialog, TX Text Control will load the selected file properly.

Please download Download [58.3 KB, ZIP] the full source code for this sample.

The minimum requirements for this sample application are TX Text Control .NET trial version and Delphi 8.0 for Microsoft .NET Framework.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place