我想一按按钮就把“第二行”这三个字插入到文本框的第二行,请勿代码要怎么写?如果你对我上面文字表述的问题有误解,请查看下面的图片。谢谢!!因为CSDN中不能贴图,所以我只能给出链接地址。GIF图片,绝对不会有病毒的。^_^。http://www.chinadforce.com/attachments/day_041103/ggg_leEM0d0gS3R9.gif

解决方案 »

  1.   

    记得有个 API 是可以 读取文本框的某一行的某个字是什么.
    感觉用那个就可以实现.我这没有源码你去网上搜搜.
      

  2.   

    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
       
       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
      

  3.   

    很简单:
    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
      

  4.   

    用Instr函数找到第一个vbcrlf的位置,然后设定SelStart等于该位置+1(或+2),然后再设定SelText为想插入的字符串