我如何让richtextbox只显示999行呢。
由于richbox中显示了颜色,如果直接判断行数大于999,就richtextbox.text = ....
这样的话就可以实现。但是有个问题,richbox中我显示了各种颜色,如果简单的这样操作后,颜色就没有了,请问该如何实现呢?

解决方案 »

  1.   


    Private Sub RichTextBox1_KeyPress(KeyAscii As Integer)
    Dim i As Long
    i = SendMessageByNum(RichTextBox1.hWnd, EM_GETLINECOUNT, 0, 0)
    If i > 999 Then KeyAscii = 0
    End Sub
      

  2.   

    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 Const EM_GETLINECOUNT = &HBA
     Private Sub RichTextBox1_KeyPress(KeyAscii As Integer)
    Dim i As Long
    i = SendMessageByNum(RichTextBox1.hWnd, EM_GETLINECOUNT, 0, 0)
    If i > 999 Then KeyAscii = 0
    End Sub