Here is the ms help: This works
With the RichTextBox control the end user can change various attributes of text such as font, font size, and font color. In this scenario, three ComboBox controls appear on an application's toolbar to show attributes of text in the RichTextBox control:
Using these ComboBox controls, the user can select a font, font color, and font size to apply to selected text.
The following objects are used in this scenario:
Form object named "frmRTF"
Toolbar control named "tlbRTF"
ComboBox control named "cmbFontColor"
ComboBox control named "cmbFontName"
ComboBox control named "cmbFontSize"
RichTextBox control named "rtfData"
Note The following steps are a general outline of the creation process. Each step is explained in greater detail later in this topic.
To create three combo boxes that display attributes
Set the Form object's ScaleMode to centimeters.
Create a Toolbar control.
Create three ComboBox controls on the Toolbar control.
In the Form object's Load event, populate the ComboBox controls.
In the ComboBox controls' Click event, set the SelFontName, SelFontColor, or SelFontSize property.
In the RichTextBox control's SelChange event, use the SelFontName, SelFontColor, or SelFontSize property to change the appropriate ComboBox control's List property.
Set the Form Object's ScaleMode to Centimeters
The Form object's ScaleMode property determines which measurement unit is used for certain properties. On the RichTextBox control, the SelIndent. SelHangingIndent, and other properties, use the ScaleMode unit. For these properties, it's more convenient to use centimeters rather than twips. In addition, when creating Button objects with the PlaceHolder style, the ScaleMode property determines how the Button object's width is measured.
To set the form object's ScaleMode property to centimeters
Click the Form object.
Press F4 to display the Properties window.
Click the ScaleMode property and select 7 (centimeters).
Create a Toolbar Control
On the Toolbox, double-click the Toolbar control icon. In the Properties window, double-click Name and change the name of the control to tlbRTF.
Create Three ComboBox Controls
Three ComboBox controls will be placed on the Toolbar. Each ComboBox control will be populated with font attributes.
To create three ComboBox controls
On the Toolbox, click the ComboBox control icon.
Draw a ComboBox control on the Toolbar control.
Set the Name property for each of the three ComboBox controls according to the following table:ComboBox Property Value
ComboBox1 Name cmbFontName
ComboBox2 Name cmbFontSize
ComboBox3 Name cmbFontColor
Populate the ComboBox Controls
The ComboBox controls must also be populated with appropriate values. The following code populates each ComboBox control in the Form_Load event.
Private Sub Form_Load()
' Add colors to cmbFontColor.
.ListIndex = 0
Dim i As Integer
For i = 0 to Screen.FontCount - 1
' Set ListIndex to 0.
.ListIndex = 0
' Populate the combo with sizes in
' increments of 2.
For i = 8 To 72 Step 2
' Set ListIndex to 0
.ListIndex = 1 ' size 10.
In the ComboBox Controls' Click event: Set the SelFontName, SelColor, or SelFontSize Property
To set the font, color, and font size for a RichTextBox control, use the SelFontName, SelColor, and SelFontSize properties. For each of the ComboBox controls, set the appropriate property in the Click event. After setting the property, you may want to set the focus back to the RichTextBox control:
Private Sub cmbFontName_Click()
rtfData.SelFontName = cmbFont
Private Sub cmbFontSize_Click()
rtfData.SelFontSize = cmbFontSize.Text
Private Sub cmbFontColor_Click()
' Change font colors of text using the
' Select Case statement with the ListIndex of the
' ComboBox control. Set the colors with
' the intrinsic constants for color.
Select Case cmbFontColor.ListIndex
.SelColor = vbBlack
.SelColor = vbBlue
.SelColor = vbRed
.SelColor = vbGreen
' Return focus to the RichTextbox control.
In the SelChange Event: Use the SelFontName, SelColor, or SelFontSize property to change the appropriate ComboBox control's List property
The ComboBox control can also be used to notify the user of text attributes as the insertion point is moved in the RichTextBox control. The SelChange event occurs either when the insertion point is moved, or when selected text is changed. Thus, in the SelChange event, check the SelFontName, SelFontColor, and SelFontSize properties and reset the appropriate ComboBox control.
Private Sub rtfData_SelChange()
' SelFontSize returns the font size, or Null if
' it's mixed.
If Not IsNull(rtfData.SelFontSize) Then
cmbFontSize.Text = rtfData.SelFontSize
' Show Font name in the ComboBox.
cmbFont.Text = rtfData.SelFontName
' Show color of text in the ComboBox. Use the
' intrinsic constants for color to determine
' the color of the text.
Select Case rtfData.SelColor
cmbFontColor.ListIndex = 0
cmbFontColor.ListIndex = 1
cmbFontColor.ListIndex = 2
cmbFontColor.ListIndex = 3