Results 1 to 11 of 11

Thread: [RESOLVED] TextBox.GetLastVisibleLineIndex-Method not available

Threaded View

  1. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [RESOLVED] TextBox.GetLastVisibleLineIndex-Method not available

    here's an extensions module with 2 functions that extend the textbox class:

    vb Code:
    1. Module extensions
    2.  
    3.     Private Declare Function SendMessage Lib "user32" _
    4.             Alias "SendMessageA" (ByVal hwnd As Integer, _
    5.             ByVal wMsg As Integer, ByVal wParam As Integer, _
    6.             ByVal lParam As Integer) As Integer
    7.  
    8.     Private Const EM_GETFIRSTVISIBLELINE As Integer = &HCE
    9.  
    10.     <System.Runtime.CompilerServices.Extension()> _
    11.     Public Function GetFirstVisibleLineIndex(ByVal instance As TextBox) As Integer
    12.         Return SendMessage(instance.Handle.ToInt32, EM_GETFIRSTVISIBLELINE, 0, 0)
    13.     End Function
    14.  
    15.     <System.Runtime.CompilerServices.Extension()> _
    16.     Public Function GetLastVisibleLineIndex(ByVal instance As TextBox) As Integer
    17.         Dim height As Integer = CInt(instance.CreateGraphics().MeasureString("0123456789", instance.Font, instance.Width).Height)
    18.         Dim bottomLineIndex As Integer = ((instance.ClientSize.Height \ height) + SendMessage(instance.Handle.ToInt32, EM_GETFIRSTVISIBLELINE, 0, 0)) - 1
    19.         Return If(bottomLineIndex <= instance.Lines.GetUpperBound(0), bottomLineIndex, instance.Lines.GetUpperBound(0))
    20.     End Function
    21.  
    22. End Module

    to use the functions, add the module to your project, then:

    vb Code:
    1. MsgBox(TextBox1.GetFirstVisibleLineIndex)
    2. MsgBox(TextBox1.GetLastVisibleLineIndex)
    Last edited by .paul.; Mar 25th, 2010 at 01:25 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width