Return or set font color and styles for a RichEdit control in the following formats: Bold, Italic, Strikethru, and Underline. SelCharOffset determines the superscript or subscript distance from the baseline.
object.SelBold [= variant]
object.SelItalic [= variant]
object.SelFontName [= variant]
object.SelFontSize [= variant]
object.SelStrikeout [= variant]
object.SelUnderline [= variant]
object.SelColor [= variant]
object.SelCharOffset [= variant]
object:RichEdit Ocx Object
Use these font properties to format the selected text in a RichEdit control.
The settings for variant are:
NullThe selection or character following the insertion point contains characters that have a mix of the appropriate font styles.
valueTrue or name for SelFontName, size in points for SelFontSize, and RGB-value for SelColor. All the characters in the selection, or character following the insertion point, have the appropriate font style.
False (Default) or empty string for SelFontName and size in points for SelFontSize. None of the characters in the selection or character following the insertion point have the appropriate font style.
To distinguish between the values of Null and False when reading these properties at run time, use the IsNull function with the If...Then...Else statement. See example.
SelCharOffset returns or sets a value that determines whether text appears on the baseline (normal), as a superscript above the baseline, or as a subscript below the baseline. The value can be 0 indicating that the characters appear on the baseline, positive indicating above the baseline, and negative indicating below the baseline (in twips).
Global Int32 rdpos
Ocx RichEdit red = "", 10, 10, 200, 200 : .MultiLine = True : .BorderStyle = 1
Ocx Command cmd1 = "Change Font", 230, 10, 120, 22
Ocx Command cmd2 = "Change Colour", 230, 40, 120, 22
Ocx Option opt(0) = "Subscript", 230, 70, 120, 14
Ocx Option opt(1) = "Normal", 230, 85, 120, 14 : opt(1).Value = 1
Ocx Option opt(2) = "Superscript", 230, 100, 120, 14
red.SetFocus
Do : Sleep : Until Me Is Nothing
Sub cmd1_Click
Ocx CommDlg cd
cd.Flags = cdfBoth
cd.ShowFont
With red
.SelFontName = cd.FontName
.SelFontSize = cd.FontSize
.SelBold = cd.FontBold
.SelItalic = cd.FontItalic
.SelStrikeout = cd.FontStrikethru
.SelUnderline = cd.FontUnderline
End With
red.SetFocus
EndSub
Sub cmd2_Click
Ocx CommDlg cd
cd.Flags = cdcFullOpen | cdcRgbInit
cd.Color = red.SelColor
cd.ShowColor
red.SelColor = cd.Color
red.SetFocus
EndSub
Sub opt_Click(Index%)
red.SelCharOffset = 90 * (Index% - 1)
red.SetFocus
EndSub
Sub red_GotFocus
red.SelStart = rdpos
EndSub
Sub red_LostFocus
If Not red Is Nothing Then rdpos = red.SelStart
EndSub
To find if some or all of the selected text matches a certain criteria, use the following code:
If IsNull(RichEdit1.SelBold) = True Then
' Code to run when selection is mixed.
ElseIf RichEdit1.SelBold = False Then
' Code to run when selection is not bold.
End If
Null differs from zero, these properties can only be queried with IsNull().
{Created by Sjouke Hamstra; Last updated: 22/10/2014 by James Gaite}