Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDouble-click to strike a line in a RichTextBox
DescriptionThis 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.
KeywordsRichTextBox, RTF, font, strikethrough, strike through
CategoriesControls, 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated