TX Text Control Source Code Library

Building a symbol dialog box

Microsoft Word has a dialog box that enables end users to insert symbols using different symbol fonts in to their current document.

This sample application shows how to build such a dialog for your TX Text Control based applications.

The concept is not difficult, but the implementation is a little tricky, especially if you are doing it for the first time.

First of all, we simply fill an ArrayList with all characters from KeyCode 0 to 255.

For a As Integer = 0 To 255 mySymbols.Add(Chr(a)) Next

Then we create a Label control for every character in the ArrayList. These labels are placed side-by-side, so that they look like a grid.

Each Label gets one character code from the ArrayList and the font which is selected in the Combobox.

For Each symbol As String In mySymbols Dim newBox As New System.Windows.Forms.Label newBox.Font = smallFont newBox.Text = symbol AddHandler newBox.Click, AddressOf SelectEvent AddHandler newBox.DoubleClick, AddressOf Selected Me.Panel1.Controls.Add(newBox) Next

Additionally, we attach an event handler to every inserted Label control. On the Click event, we display the current symbol in a bigger font. If the user double clicks on a symbol, the current character is inserted into TX Text Control.

tx.Selection.FontName = curSymbolBox.Font.Name tx.Selection.Text = curSymbolBox.Text

Additionally, we show in the sample how to use a Singleton pattern to ensure that only one instance of the dialog is open. Generally, you would use the ShowDialog() method of a form, but we would like to open a dialog and be able to edit the content of the main form.

The minimum requirements for this sample application are TX Text Control .NET for Windows Forms trial version and Visual Studio .NET 2003.

 
 

Products

Support

Downloads

Corporate

Buy Now