RTFEdit ActiveX32 Bit OCX ControlTechnical Document |
|
Example :
Private Sub RTFEdit1_Click()
MsgBox "Click event"
End Sub
Example :
Private Sub RTFEdit1_MouseUp (Button As Integer, Shift As Integer,
X As Single, Y As Single)
MsgBox "Mouse Up"
End Sub
Example :
Private Sub RTFEdit1_MouseMove (Button As Integer, Shift As Integer,
X As Single, Y As Single)
MsgBox "Mouse Move"
End Sub
Example :
Private Sub RTFEdit1_DblClick()
MsgBox "Double Click event"
End Sub
Example :
Private Sub RTFEdit1_KeyDown (KeyCode As Integer, Shift As Integer)
MsgBox KeyCode & " Pressed"
End Sub
Example :
Private Sub RTFEdit1_KeyPress (KeyCode As Integer, Shift As Integer)
MsgBox KeyCode & " Pressed"
End Sub
Example :
Private Sub RTFEdit1_SelChange()
If RTFEit1.SelBold Then
MsgBox "The Current Style is BOLD"
End If
End Sub
Syntax :
object.SaveFile(pathname, filetype)
The SaveFile method syntax has these parts:
|
|
|
rtfRTF | 0 (Default) RTF. | The RTFEdit control saves its contents as an .RTF file. |
rtfText | 1 Text. | The RTFEdit control saves its contents as a text file. |
Private Sub Command1_Click()
CommonDialog1.ShowSave
RTFEdit1.SaveFile CommonDialog1.Filename,
rtfRTF
End Sub
Syntax :
Object.SelPrint(hdc)
The SelPrint method syntax has these parts:
|
|
object | An object expression that evaluates to a RTFEdit control. |
hdc | The device context of the device you plan to use to print the contents of the control. |
RTFEdit1.SelPrint(Printer.hDC)
Notice that the hDC property of the Printer object is used to specify
the device context argument of the SelPrint method.
Note If you use the Printer object as the destination of
the text from the RTFEdit control, you must first initialize the device
context of the Printer object by printing something like a zero-length
string.
Example :
This example prints the formatted text in a RTFEdit control. To try
this example, put a RTFEdit control, a CommonDialog control, and a CommandButton
control on a form. Paste this code into the Click event of the CommandButton
control. Then run the example.
Private Sub Command1_Click()
CommonDialog1.Flags = cdlPDReturnDC
+ cdlPDNoPageNums
If RTFEdit1.SelLength =
0 Then
CommonDialog1.Flags = CommonDialog1.Flags + cdlPDAllPages
Else
CommonDialog1.Flags = CommonDialog1.Flags + cdlPDSelection
End If
CommonDialog1.ShowPrinter
Printer.Print ""
RTFEdit1.SelPrint CommonDialog1.hDC
End Sub
Syntax :
RTFEdit.EnableButton IndexOfButton , StatusOfButton
Remarks :
Buttons numberd from 1 to 14. The font and fontsize combo boxes on
the toolbar has same index of 14.
Example :
Private Sub Form_Load()
RTFEdit1.EnabledButton 1
, False 'This will disable the color selection button
End Sub
Syntax :
RTFEdit.ContextMenu StatusOfMenu
Example :
Private Sub Form_Load()
RTFEdit1.ContextMenu
False 'This will disable the context menu
End Sub
Syntax :
RTFEdit.ShowToolbar StatusOfToolbar
Example :
Private Sub Form_Load()
RTFEdit1.ShowToolbar
False 'Make toolbar and margin bars invisible
End Sub
Syntax :
object.LoadFile pathname, filetype
The LoadFile method syntax has these parts:
|
|
object | Required. An object expression that evaluates to a RTFEdit Control. |
pathname | Required. A string expression defining the path and filename of the file to load into the control. |
filetype | Optional. An integer or constant that specifies the type of file loaded, as described in Settings. |
|
|
|
rtfRTF | 0 (Default) RTF. | The file loaded must be a valid .RTF file. |
rtfText | 1 Text. | The RTFEdit control loads any text file. |
Example :
This example displays a dialog box to choose an .RTF file, then loads
that file into a RTFEdit control. To try this example, put a RTFEdit control,
a CommandButton control, and a CommonDialog control on a form. Paste this
code into the General Declarations section of the form. Then run the example.
Private Sub Command1_Click()
CommonDialog1.Filter = "Rich
Text Format files|*.rtf"
CommonDialog1.ShowOpen
RTFEdit1.LoadFile CommonDialog1.Filename,
rtfRTF
End Sub
Syntax :
RTFEdit.VisibleButton IndexOfButton , StatusOfButton
Remarks :
Buttons numberd from 1 to 14. The font and fontsize combo boxes on
the toolbar has same index of 14.
Example :
Private Sub Form_Load()
RTFEdit1.VisibleButton 1
, False 'This will make the color selection button invisible.
End Sub
Syntax :
RTFEdit.BackColo [= VBColor]
Settings :
The settings for value are:
|
|
|
Null | Neither. | The current selection spans more than one paragraph with different alignments. |
rtfLeft | 0 (Default) Left. | The paragraph is aligned along the left margin. |
rtfRight | 1 Right. | The paragraph is aligned along the right margin. |
rtfCenter | 2 Center. | The paragraph is centered between the left and right margins. |
If IsNull(RTFEdit1.SelAlignment) = True Then
' Code to run when selection
is mixed.
ElseIf RTFEdit1.SelAlignment = 0 Then
' Code to run when selection
is left aligned.
End If
Example :
This example uses an array of OptionButton controls to change the paragraph
alignment of selected text in a RTFEdit control, but only if text is selected.
The indices of the controls in the array correspond to settings for the
SelAlignment property. To try this example, put a RTFEdit control and three
OptionButton controls on a form. Give all three of the OptionButton controls
the same name and set their Index property to 0, 1, and 2. Paste this code
into the Click event of the OptionButton control. Then run the example.
Private Sub Option1_Click(Index As Integer)
If RTFEdit1.SelLength >
0 Then
RTFEdit1.SelAlignment = Index
End If
End Sub
Syntax :
RTFEdit.SelBold [= value]
RTFEdit.SelItalic [= value]
RTFEdit.SelStrikethru [= value]
RTFEdit.SelUnderline [= value]
[Value] is a Boolean expression or constant that determines the font
style.
Example :
Private Sub Command1_Click()
RTFEdit1.SelBold
= True
End Sub
Syntax :
RTFEdit.SelBullet [= value]
[Value] is a Boolean expression or constant that determines the font
style.
Example :
Private Sub Command1_Click()
RTFEdit1.SelBullet
= True
End Sub
Syntax :
RTFEdit.SelColor = [Color]
[Color] Is a value that specifies a color.
Example :
Private Sub Command1_Click()
RTFEdit1.SelColor
= VbRed
End Sub
Syntax :
RTFEdit.SelFontName = [String]
RTFEdit.SelFontSize = [Value]
[String] Is a windows installed font name.
[Value] Is font size in points.
Example :
Private Sub Command1_Click()
RTFEdit1.SelFontName
= "Arial"
RTFEdit1.SelFontSize
= 22
End Sub
|
|
object | An object expression that evaluates to a RTFEdit control. |
number | A numeric expression specifying the number of characters selected. For SelLength and SelStart, the valid range of settings is 0 to text length --- the total number of characters in the edit area RTFEdit control. |
index | A numeric expression specifying the starting point of the selected text, as described in Settings. |
value | A string expression containing the selected text. |
Private Sub Form_Load ()
RTFEdit1.Text = "This is
a sample text for using with RTFEdit ActiveX control"
End Sub
Private Sub Form_Click ()
Dim Search, Where ' Declare variables.
' Get search string from user.
Search = InputBox("Enter text to be found:")
Where = InStr(RTFEdit1.Text, Search) ' Find string in text.
If Where Then ' If found,
RTFEdit1.SelStart = Where - 1 ' set selection start and
RTFEdit1.SelLength = Len(Search) ' set selection length.
Else
MsgBox "String not found." ' Notify user.
End If
End Sub
Syntax :
object.SelRTF [= string]
Remarks :
Setting the SelRTF property replaces any selected text in the RTFEdit
control with the new string. This property returns a zero-length string
("") if no text is selected in the control.
You can use the SelRTF property along with the Print function to write
.RTF files.
Example :
This example saves the highlighted contents of a RTFEdit control to
an .RTF file. To try this example, put a RTFEdit control and a CommandButton
control on a form. Paste this code into the Click event of the CommandButton
control. Then run the example.
Private Sub Command1_Click ()
Open "mytext.rtf" For Output
As 1
Print #1, RTFEdit1.SelRTF
Close 1
End Sub
Syntax :
object.Text [= string]
Syntax :
object.ToolTipText [= string]
Remarks:
To bind a RTFEdit control to a field in a database at run time, you
must specify a Data control in the DataSource property at design time using
the Properties window.
To complete the connection with a field in the Recordset managed by
the Data control, you must also provide the name of a Field object in the
DataField property. Unlike the DataField property, the DataSource property
setting isn't available at run time.
Syntax:
object.DataField [= value]
The DataField property syntax has these parts:
Part | Description |
object | An object expression that evaluates to a RTFEdit control. |
value | A string expression that evaluates to the name of one of the fields in the Recordset object specified by a Data control's RecordSource and DatabaseName properties. |