关于richtextbox
pgcat 2005-07-29 04:09:48
Const EM_GETLINECOUNT = &HBA
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim LastLine As Long '注释:最后的行数
Dim LineHeight '注释:每行的高度
Dim nums
Private Sub Form_Load()
Set Me.Font = rchText.Font
LineHeight = Me.TextHeight("样本")
rchText.Height = LineHeight
End Sub
Private Sub rchText1_Change()
Dim Ret As Long
Ret = SendMessage(rchText1.hWnd, EM_GETLINECOUNT, 0, 0&) '注释:取行数
If Ret <> LastLine Then
If rchText1.Height + rchText1.Top + LineHeight > Me.ScaleHeight And Ret > 1 Then
If LastLine <= Ret - 1 Then
Exit Sub '注释:如果已经是最大高度,保持
End If
LastLine = Ret - 1 '注释:超过最大高度
Else
LastLine = Ret
End If
rchText1.Height = LastLine * LineHeight '注释:修改高度
End If
End Sub
Private Sub Text1_GotFocus(Index As Integer)
LastLine = SendMessage(rchText1.hWnd, EM_GETLINECOUNT, 0, 0&)
End Sub
代码功能是richtextbox 高度随行数增加而增加
dan但是运行的时候 rchtext1的第一行总是滚到最上面,看不到。而最好多出来一空白行!!!!!!!! 请帮忙看看 分还好商量:)