[RESOLVED] TextBox.GetLastVisibleLineIndex-Method not available
Hi all,
I found a TextBox.GetLastVisibleLineIndex-method in the online documentation. But it is not available in my code. I´m using Visual Basic 2008 Express Edition. Is that the reason?
Greetings,
TheTree
Re: TextBox.GetLastVisibleLineIndex-Method not available
I don't know where you saw that but here's the methods list of the TextBox on msdn and GetLastVisibleLineIndex is not one of them.
Re: TextBox.GetLastVisibleLineIndex-Method not available
it's listed in object browser
Re: TextBox.GetLastVisibleLineIndex-Method not available
and it´s listed here: ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.de/fxref_system.windows.controls/html/e90bae0d-ddb7-ee24-67ad-f2228bb17cd7.htm
Greetings,
TheTree
Re: TextBox.GetLastVisibleLineIndex-Method not available
Re: TextBox.GetLastVisibleLineIndex-Method not available
Hi .paul,
thanks for your reply.
What do I have to do, to use WPF-methods. Can I install something to Visual Basic 2008 Express Edition to use it?
Greetings,
TheTree
Re: TextBox.GetLastVisibleLineIndex-Method not available
Yeah I just noticed that it IS in textbox members list even if its not in its methods list on msdn.
As we can see here its assembly is PresentationFramework.
that explains it, thanks .paul.
Re: TextBox.GetLastVisibleLineIndex-Method not available
you can do it with the sendmessage API:
vb Code:
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
vb Code:
Dim height As Integer = CInt(TextBox3.CreateGraphics().MeasureString(TextBox3.Lines(0), TextBox3.Font, TextBox3.Width).Height)
MsgBox(((TextBox3.ClientSize.Height \ height) + SendMessage(TextBox3.Handle.ToInt32, EM_GETFIRSTVISIBLELINE, 0, 0)) - 1)
Re: TextBox.GetLastVisibleLineIndex-Method not available
Hi .paul.,
Thank you very much. Now its running!
I´m so glad!
:wave:
Thanks to Alex, too.
Greetings,
TheTree
Re: [RESOLVED] TextBox.GetLastVisibleLineIndex-Method not available
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)
Re: [RESOLVED] TextBox.GetLastVisibleLineIndex-Method not available
Wow. That´s perfect!
Thank you very much.
TheTree