记得有个 API 是可以 读取文本框的某一行的某个字是什么. 感觉用那个就可以实现.我这没有源码你去网上搜搜.
Option Explicit Private Const EM_GETLINE = &HC4 Private Const EM_GETLINECOUNT = &HBA Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Sub RtlMoveMemory Lib "KERNEL32" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)Private Sub Command1_Click() Dim lcount As Long Dim i, x As Integer Dim str As String
Dim S As String, Length As Integer Dim str1 As String
str1 = "" For i = 0 To lcount - 1 Length = 80 S = String(Length, Chr(0)) RtlMoveMemory ByVal S, Length, 2 SendMessage Text1.hwnd, EM_GETLINE, i, ByVal S S = Left(S, InStr(S, Chr(0)) - 1) Debug.Print S, i str1 = str1 & S & vbCrLf If i = 0 Then str1 = str1 & "第二行" & vbCrLf End If
Next i
Text1.Text = str1 End Sub
很简单: Private Sub Command1_Click() Dim mylines() As String Dim i As Integer mylines = Split(Text1, vbNewline) ReDim Preserve mylines(Ubound(mylines)+1) For i = Ubound(mylines) To 2 Step -1 mylines(i) = mylines(i - 1) Next i mylines(1) = "第二行" Text1 = Join(mylines, vbNewline) End Sub
感觉用那个就可以实现.我这没有源码你去网上搜搜.
Private Const EM_GETLINE = &HC4
Private Const EM_GETLINECOUNT = &HBA
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Sub RtlMoveMemory Lib "KERNEL32" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)Private Sub Command1_Click()
Dim lcount As Long
Dim i, x As Integer
Dim str As String
Dim S As String, Length As Integer
Dim str1 As String
lcount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)
str1 = ""
For i = 0 To lcount - 1
Length = 80
S = String(Length, Chr(0))
RtlMoveMemory ByVal S, Length, 2
SendMessage Text1.hwnd, EM_GETLINE, i, ByVal S
S = Left(S, InStr(S, Chr(0)) - 1)
Debug.Print S, i
str1 = str1 & S & vbCrLf
If i = 0 Then
str1 = str1 & "第二行" & vbCrLf
End If
Next i
Text1.Text = str1
End Sub
Private Sub Command1_Click()
Dim mylines() As String
Dim i As Integer
mylines = Split(Text1, vbNewline)
ReDim Preserve mylines(Ubound(mylines)+1)
For i = Ubound(mylines) To 2 Step -1
mylines(i) = mylines(i - 1)
Next i
mylines(1) = "第二行"
Text1 = Join(mylines, vbNewline)
End Sub