| |

VerySource

 Forgot password?
 Register
Search
View: 3228|Reply: 13

How to go to a certain line in richtextbox

[Copy link]

1

Threads

7

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2021-3-11 17:30:02
| Show all posts |Read mode
How to go to a certain line in richtextbox
Form link.Text1.SelStart = SendMessage(Text1.hWnd, EM_LINEINDEX, i-1, 0&)
i is the line number of a line to go to
I don’t know why I can’t go to the line where the line is blank. For example, if the second line is a blank line, then I want to go to the second line. Vb always cannot go to the second line. If the third line is not a blank line, then it Just go to line 3 ------ I don't know why
Reply

Use magic Report

1

Threads

7

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2021-3-11 17:45:01
| Show all posts
Excuse me, is there any other way to go to a certain line in richtextbox? It is a blank line to go to the line. Thank you
Reply

Use magic Report

0

Threads

34

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2021-3-11 18:00:02
| Show all posts
Dim a
a = InStr(RichTextBox1.Text, vbCrLf&vbCrLf)
If a = 0 Then a = Len(RichTextBox1.Text)
RichTextBox1.SetFocus
RichTextBox1.SelStart = a + 1
Reply

Use magic Report

0

Threads

14

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2021-3-11 18:30:01
| Show all posts
Private Sub Command1_Click()
Dim n As Long
n = CLng(InputBox("How many lines the cursor points to", "info", Int(Rnd * 100)))
RichTextBox1.SetFocus
SendKeys "^{home}"
SendKeys "{down "&n&"}"
End Sub

Private Sub Form_Load()
RichTextBox1.Text = Replace(Replace(String(100, "1"), "1", "012340"), "0", vbCrLf)
End Sub
Reply

Use magic Report

0

Threads

14

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2021-3-11 18:45:01
| Show all posts
or:
Option Explicit
Const EM_LINESCROLL =&HB6
Private Declare Function SendMessage Lib "User32" Alias ​​"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Long) As Long
Private Sub Command1_Click()
RichTextBox1.SetFocus
RichTextBox1.SelStart = 0
Randomize
Dim n As Long
n = CLng(InputBox("How many lines the cursor points to", "info", Int(Rnd * 100)))-1
SendMessage RichTextBox1.hWnd, EM_LINESCROLL, 0, n&
End Sub

Private Sub Form_Load()
Dim i As Long, arr(1 To 500) As String
For i = 1 To 500
arr(i) = IIf(i Mod 9> 7, "", "第"&i&"line")
Next
RichTextBox1.Text = Join(arr, vbCrLf)
End Sub
Reply

Use magic Report

1

Threads

7

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2021-3-11 19:00:01
| Show all posts
talent00168hello
SendKeys "{down "&n&"}" ------What does n mean?
for i=1 to n
SendKeys "{down}"
next


But this method is too time consuming. Originally, the purpose of the program I compiled was to delete blank lines and blank lines containing spaces. Would it be too time-consuming to use this method?
Reply

Use magic Report

1

Threads

7

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2021-3-11 19:45:01
| Show all posts
talent00168hello
n = CLng(InputBox("How many lines the cursor points to", "info", Int(Rnd * 100)))-1
SendMessage RichTextBox1.hWnd, EM_LINESCROLL, 0, n&Is this code? So I tried, he didn't respond
Reply

Use magic Report

0

Threads

14

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2021-3-11 20:30:01
| Show all posts
Dim n As Long
n = CLng(InputBox("How many lines the cursor points to", "info", Int(Rnd * 100)))-1
SendKeys "{down "&n&"}" ------What does n mean? n you specify
Reply

Use magic Report

0

Threads

14

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2021-3-11 20:45:01
| Show all posts
talent00168hello
n = CLng(InputBox("How many lines the cursor points to", "info", Int(Rnd * 100)))-1
SendMessage RichTextBox1.hWnd, EM_LINESCROLL, 0, n&Is this code? So I tried, he didn't respond
------------------
What is wrong? Paste your code
Reply

Use magic Report

1

Threads

7

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2021-3-11 21:15:01
| Show all posts
talent00168hello

Const EM_LINESCROLL =&HB6

      Private Declare Function SendMessage Lib "User32" Alias ​​_
      "SendMessageA" _
         (ByVal hWnd As Long, _
          ByVal wMsg As Integer, _
          ByVal wParam As Integer, _
          ByVal lParam As Long) As Long

      Private Sub Form_Load()
         Dim intLineIndex As Integer, intWordIndex As Integer

         'Initialize Text1.
         Text1.Font = "Courier New"
         Text1.Text = ""
         For intLineIndex = 1 To 25'Add 25 lines of text.
            Text1.Text = Text1.Text&"Line"&Str$(intLineIndex)
            For intWordIndex = 1 To 5'Make each line 12 words
                                                'long.
               Text1.Text = Text1.Text&"Word"&Str$(intWordIndex)
            Next intWordIndex
            Text1.Text = Text1.Text&vbCrLf
         Next intLineIndex

         Command1.Caption = "Vertical"
         Command2.Caption = "Horizontal"
      End Sub

      Private Sub Command1_Click()
         Dim lngRet As Long

         lngRet = SendMessage(Text1.hWnd, EM_LINESCROLL, 0, 5&)
      End Sub

      Private Sub Command2_Click()
         Dim lngRet As Long

         lngRet = SendMessage(Text1.hWnd, EM_LINESCROLL, 5, 0&)
      End Sub


But this method is the scrolling function of the TextBox control, it cannot position the cursor and cannot text1.selstart=
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list