here's an extensions module with 2 functions that extend the textbox class:
vb Code:
Module extensions Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" (ByVal hwnd As Integer, _ ByVal wMsg As Integer, ByVal wParam As Integer, _ ByVal lParam As Integer) As Integer Private Const EM_GETFIRSTVISIBLELINE As Integer = &HCE <System.Runtime.CompilerServices.Extension()> _ Public Function GetFirstVisibleLineIndex(ByVal instance As TextBox) As Integer Return SendMessage(instance.Handle.ToInt32, EM_GETFIRSTVISIBLELINE, 0, 0) End Function <System.Runtime.CompilerServices.Extension()> _ Public Function GetLastVisibleLineIndex(ByVal instance As TextBox) As Integer Dim height As Integer = CInt(instance.CreateGraphics().MeasureString("0123456789", instance.Font, instance.Width).Height) Dim bottomLineIndex As Integer = ((instance.ClientSize.Height \ height) + SendMessage(instance.Handle.ToInt32, EM_GETFIRSTVISIBLELINE, 0, 0)) - 1 Return If(bottomLineIndex <= instance.Lines.GetUpperBound(0), bottomLineIndex, instance.Lines.GetUpperBound(0)) End Function End Module
to use the functions, add the module to your project, then:
vb Code:
MsgBox(TextBox1.GetFirstVisibleLineIndex) MsgBox(TextBox1.GetLastVisibleLineIndex)




Reply With Quote