关于richtextbox的几个问题,50分(每问给10分)~~小弟最近正在学习使用richtextbox,有些问题希望大家解答,谢谢各位了~1.如何删除光标所在行的内容?
2.如何删除指定行(第N行)的内容?
3.如何读取第N行的内容(找到过资料,但是无法读出中文字符而呈现乱码,这个问题一定要解决~)?
4.如何选择某一行中的某个字符串使它能进行颜色改变或者加粗加下划线之类的操作?
5.有没有办法像某些字处理软件一样自动在文本框前面加上行数统计?
以上问题,希望大家指点~回答的时候注明问题对应的编号,我好按照回答的题目数量给分。
谢谢大家!

解决方案 »

  1.   

    头两个问题的解决办法:
    Private Sub ClearCurrentLine()
        RichTextBox1.SetFocus
        SendKeys "{home}"
        SendKeys "+{end}"
        SendKeys "{del}"
    End SubPrivate Sub ClearLine(index As Integer)
        RichTextBox1.SetFocus
        SendKeys "^{home}"
        Dim i As Integer
        For i = 1 To index - 1
            SendKeys "{down}"
        Next
        Call ClearCurrentLine
    End Sub现在下班了,先回家,后面三个待下回分解!
      

  2.   

    冒着被老婆骂的危险,
    第三个问题:
    Private Sub GetLineText(index As Integer)
        RichTextBox1.SetFocus
        SendKeys "^{home}"
        Dim i As Integer
        For i = 1 To index - 1
            SendKeys "{down}"
        Next
        SendKeys "{home}"
        SendKeys "+{end}"
        DoEvents
        MsgBox RichTextBox1.SelText
    End Sub
      

  3.   

    第四个不明白你的意思
    第五个:
    Private Sub GetLineCount()
        Dim str1 As String
        Dim str2 As String
        str1 = RichTextBox1.Text
        str2 = Replace(str1, vbCrLf, " ")
        MsgBox "共" & Len(str1) - Len(str2) & "行"
    End Sub呵呵,先拿40分,回家挨批去喽
      

  4.   

    第四个(效率比较低下):
    Private Sub SetStrBold(index As Integer, str As String)
    'index为第几行,str为查找的字符串
        Dim i As Integer
        Dim intStart As Integer
        Dim strTmp As String
        
        RichTextBox1.SetFocus
        SendKeys "^{home}": DoEvents
        
        For i = 1 To index - 1
            SendKeys "{down}": DoEvents
        Next
        SendKeys "{home}": DoEvents
        SendKeys "+{end}": DoEvents
        
        strTmp = RichTextBox1.SelText
        intStart = 1
        Do While intStart <> 0
            DoEvents
            intStart = InStr(IIf(intStart = 1, 1, intStart + 1), strTmp, str)
            If intStart <> 0 Then
                SendKeys "{home}": DoEvents
                For i = 1 To intStart - 1
                    SendKeys "{right}": DoEvents
                Next
                For i = 1 To Len(str)
                    SendKeys "+{right}": DoEvents
                Next
                DoEvents
                RichTextBox1.SelBold = True
            End If
        Loop
    End Sub
      

  5.   

    谢谢chewinggum(口香糖)~分数已经全部送到~