/
Form1.vb
42 lines (32 loc) · 1.23 KB
/
Form1.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraRichEdit.Commands
Imports DevExpress.XtraRichEdit.API.Native
Namespace RichEditSelectSpecificLine
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
SelectCurrentLine()
End Sub
Private Sub SelectCurrentLine()
Dim startOfLineCommand As New StartOfLineCommand(richEditControl1)
Dim endOfLineCommand As New EndOfLineCommand(richEditControl1)
startOfLineCommand.Execute()
Dim start As Integer = richEditControl1.Document.CaretPosition.ToInt()
endOfLineCommand.Execute()
Dim length As Integer = richEditControl1.Document.CaretPosition.ToInt() - start
Dim range As DocumentRange = richEditControl1.Document.CreateRange(start, length)
Dim range2 As DocumentRange = richEditControl1.Document.CreateRange(start, length + 1)
Dim text As String = richEditControl1.Document.GetText(range2)
If text.EndsWith(Environment.NewLine) Then
richEditControl1.Document.Selection = range2
Else
richEditControl1.Document.Selection = range
End If
End Sub
End Class
End Namespace