2012-05-24 83 views

回答

2

RichTextBox中有所有你需要的方法,你只需要其中的多個。首先,你需要鼠標的位置映射到一個字符索引:

Private Sub RichTextBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) 
    Dim box = DirectCast(sender, RichTextBox) 
    Dim index = box.GetCharIndexFromPosition(e.Location) 

然後,你需要映射的字符索引到行:

Dim line = box.GetLineFromCharIndex(index) 

然後,你需要找出線開始的地方:

Dim lineStart = box.GetFirstCharIndexFromLine(line) 

然後,你需要找出它的盡頭,這是下一行的開始減一:

Dim lineEnd = box.GetFirstCharIndexFromLine(line + 1) - 1 

然後,你需要作出選擇:

box.SelectionStart = lineStart 
    box.SelectionLength = lineEnd - lineStart 

彙總:

Private Sub RichTextBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles RichTextBox1.MouseDown 
    Dim box = DirectCast(sender, RichTextBox) 
    Dim index = box.GetCharIndexFromPosition(e.Location) 
    Dim line = box.GetLineFromCharIndex(index) 
    Dim lineStart = box.GetFirstCharIndexFromLine(line) 
    Dim lineEnd = box.GetFirstCharIndexFromLine(line + 1) - 1 
    box.SelectionStart = lineStart 
    box.SelectionLength = lineEnd - lineStart 
End Sub 
+0

我愛你!!!!!! – Ron

0

只需使用下面的代碼在Click事件處理程序

SendKeys.Send("{HOME}+{END}") 
+0

我不想選,我只是想強調這一行我點擊。 – Ron

+0

看一看。我已經更新了我的答案。 –

相關問題