Many programmers who deploy TX Text Control as an OCX in the Internet Explorer want to encapsulate all the controls that make up TX Text Control (ButtonBar, StatusBar, RulerBar and TX Text Control itself) into one UserControl. There are basically two reasons to do this:
- You only have to include one object in your HTML page.
- You can implement your own methods and properties.
In doing this, however, there is typically one problem: If you include your UserControl (that contains TX Text Control) you have no access to the TX Text Control properties and methods.
In this newsletter, we are going to show you how to access all of TX Text Control's properties from your UserControl in Internet Explorer.
The trick lies in setting a public handle to TX Text Control that enables access to the properties and methods. Consider the following code:
Public Handle As TXTextControl
In the UserControl_Initialize event you set this handle to the TX Text Control.
Private Sub UserControl_Initialize()
' set handle, so that TX properties can be called from the UserControl
Set Handle = UserControl.TXTextControl1
TXTextControl1.ButtonBarHandle = TXButtonBar1.hWnd
TXTextControl1.RulerHandle = TXRuler1.hWnd
TXTextControl1.StatusBarHandle = TXStatusBar1.hWnd
Now, using VBScript you can access the Text property of TX Text Control like this, for example:
myTX.Handle.Text = "This is a TX Text Control property!"
Additionally, we can define a customized method to insert tables in our UserControl.
Sub InsertTable(TableId As Variant, Row As Integer, Col As Integer, TableLineWidth As Integer)
' this customized method can be called directly from the UserControl
UserControl.TXTextControl1.TableInsert Row, Col, -1, TableId
UserControl.TXTextControl1.TableCellAttribute(TableId, 0, 0,
txTableCellBorderWidth) = TableLineWidth
UserControl.TXTextControl1.TableCellAttribute(TableId, 1, 0,
txTableCellBackColor) = vbRed
This method inserts a table and automatically sets the border width and the background color of the first row. This shows the advantage of using a UserControl in the Internet Explorer. This method can be called directly from the UserControl without the handle:
To test the sample HTML page, it is necessary to register the myTX.OCX manually using the small utility regsvr32.exe on your machine (use the directory where the sample is installed):
Naturally, TX Text Control should also be installed on your machine, as TX Text Control is used in the UserControl. You will also find the sources of the UserControl in the zip file, so that you can add your own methods and properties.
If you are new to TX Text Control, please view these videos: They will give you a great overview of what you can achieve.
The Newsletter Team