|
|
Title | Double-click to strike a line in a RichTextBox |
Description | This example shows how to double-click to strike a line in a RichTextBox in Visual Basic 6. The program uses the RichTextBox's SelStart property to see where the user clicked. It then uses SelStart, SelLength, and SelStrikethru to strike out the line. |
Keywords | RichTextBox, RTF, font, strikethrough, strike through |
Categories | Controls, Strings |
|
|
The program uses the RichTextBox's SelStart property to see where the user clicked. It then uses SelStart, SelLength, and SelStrikethru to strike out the line.
Note that this program looks for hard carriage returns to define the line.
|
|
' Strike or unstrike the line that contains SelStart.
Private Sub StrikeLine(rch As RichTextBox)
Dim pos As Integer
Dim txt As String
Dim txtlen As Integer
Dim crlen As Integer
Dim start_pos As Integer
Dim end_pos As Integer
' Find the previous carriage return.
txt = rch.Text
crlen = Len(vbCrLf)
pos = rch.SelStart
If pos < 1 Then pos = 1
start_pos = InStrRev(txt, vbCrLf, pos)
If start_pos > 0 Then start_pos = start_pos + crlen - 1
' Find the next carriage return.
end_pos = InStr(pos, txt, vbCrLf)
If end_pos = 0 Then end_pos = Len(txt)
rch.SelStart = start_pos
rch.SelLength = end_pos - start_pos
rch.SelStrikeThru = Not rch.SelStrikeThru
End Sub
|
|
|
|
|
|