本文介绍了关于行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户指定行号时,如何使光标集中在富文本框文本中的特定行上?

how to get the cursor focused on particular line in rich textbox''s text when user specify the line number?

推荐答案

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


这篇关于关于行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 10:09