Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to get the cursor focused on particular line in rich textbox's text when user specify the line number?
Posted

1 solution

Here is the solution for your query

VB
Public Function GetLineText(ByVal RichTextBox As RichTextBox, _
              ByVal LineNumber As Integer, _
              Optional ByVal FirstLineNumberIsZero _
              As Boolean = False) As String
    If FirstLineNumberIsZero = False Then
      LineNumber = LineNumber - 1
    End If
    If LineNumber < 0 Then Return "Line Does Not Exist" : Exit Function
    If LineNumber > RichTextBox.Lines.Count Then Return "Line Does Not Exist" : Exit Function
    Dim OldCaret As Integer = RichTextBox.SelectionStart
    Dim OldLength As Integer = RichTextBox.SelectionLength
    RichTextBox.HideSelection = False
    Dim Start As Integer = RichTextBox.GetFirstCharIndexFromLine(LineNumber)
    Dim length As Integer = RichTextBox.Lines(LineNumber).Length
    PassStart = Start
    PassLength = length
    RichTextBox.SelectionStart = Start
    RichTextBox.SelectionLength = length
    Dim LineText As String = RichTextBox.SelectedText
    RichTextBox.SelectionStart = OldCaret
    RichTextBox.SelectionLength = OldLength
    Return LineText
End Function
 
Share this answer
 
Comments
[no name] 11-May-12 1:07am    
Dude i want it for C#
btw thanks.
Andy411 11-May-12 2:17am    
Google helps you with this answer:
http://www.developerfusion.com/tools/convert/vb-to-csharp/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900