dcsimg
Results 1 to 8 of 8

Thread: [RESOLVED] Textbox built in vscrollbar, no LargeChange option?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2017
    Posts
    4

    Resolved [RESOLVED] Textbox built in vscrollbar, no LargeChange option?

    It appears that the built in vertical scroll bar for textbox has no operator for the LargeChange option. Can it be changed using a scroll API functions? I have 100,00 lines, would like to scroll by 10 or more lines a a time. Do not want to add a separate scroll bar to accomplish this if possible. I'm new to this group, not sure what to post for a answer or suggestion. using VB 2015.

    Dallas

  2. #2

    Thread Starter
    New Member
    Join Date
    Jan 2017
    Posts
    4

    Re: Textbox built in vscrollbar, no LargeChange option?

    I Know that this maybe a simple question being new to visual basic 2015, the last program I wrote was in 1993 in C++. Is there a API call to access the scroll bar LargeChange in a textbox? There must be someone to can enlighten me. I know that this question is probably lame but could use some help.

  3. #3
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,580

    Re: Textbox built in vscrollbar, no LargeChange option?

    Sadly, you don't get a lot of control over that scroll bar. It's built-in and behaves based on how system parameters tell it to behave.

    I thought that *maybe* you could get at the scroll bar via API, but Spy++ is implying to me that the TextBox is *not* hosting a real scroll bar and is instead just rendering one. Yikes. I'm not finding any examples of anyone else pulling it off via web search, either. I don't see anything in API that says much about the scroll bar either, other than there's a message you can send to get the position of the thumb. But there's nothing to *set* it.

    So if you want to control it, you'll have to write something yourself. :/

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2017
    Posts
    4

    Re: Textbox built in vscrollbar, no LargeChange option?

    Thank you Sitten, just as I thought. I tried adding a vertical scrollbar but can not attach it to the textbox text?

  5. #5
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,252

    Re: Textbox built in vscrollbar, no LargeChange option?

    I don't see an Edit type message that allows that setting, seems to be autoset based on the size of the control/font size, so just a crazy idea,... scroll some additional 10 lines when the page down/up scroll is detected...

    Code:
    Imports System.Runtime.InteropServices
    
    Public Class TextBoxEx
        Inherits TextBox
    
        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            Dim pgUp, pgDown As Boolean
    
            Select Case m.Msg
                Case WM_VSCROLL ' vert scroll detected
                    Select Case LOWORD(m.WParam) ' type of vert scroll
                        Case SB_PAGEUP
                            pgUp = True
                        Case SB_PAGEDOWN
                            pgDown = True
                    End Select
            End Select
    
            ' process msgs.
            MyBase.WndProc(m)
    
            ' exrta scrolling
            If pgDown Then ' scroll down vertically 10 lines.
                SendMessage(Me.Handle, EM_LINESCROLL, 0, 10)
            ElseIf pgUp Then ' scroll up vertically 10 lines.
                SendMessage(Me.Handle, EM_LINESCROLL, 0, -10)
            End If
        End Sub
    
        Public Shared Function LOWORD(n As Integer) As Integer
            Return n And &HFFFF
        End Function
        Public Shared Function LOWORD(n As IntPtr) As Integer
            Return LOWORD(CInt(CLng(n)))
        End Function
    
        <DllImport("user32.dll")> _
        Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
        End Function
    
        Private Const SB_PAGEUP As Int32 = 2
        Private Const SB_PAGEDOWN As Int32 = 3
        Private Const WM_VSCROLL As Int32 = &H115 ' https://msdn.microsoft.com/en-us/library/windows/desktop/bb787577(v=vs.85).aspx
    
        Private Const EM_LINESCROLL As Int32 = &HB6 ' https://msdn.microsoft.com/en-us/library/windows/desktop/bb761615(v=vs.85).aspx
        ' https://msdn.microsoft.com/en-us/library/windows/desktop/bb775456(v=vs.85).aspx
        ' The lParam parameter specifies the number of lines to scroll vertically, starting from the
        'current line. The wParam parameter specifies the number of characters to scroll horizontally, starting from the current
        'character.
    
    End Class

  6. #6
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Textbox built in vscrollbar, no LargeChange option?

    Quote Originally Posted by Dosmith54 View Post
    I Know that this maybe a simple question being new to visual basic 2015, the last program I wrote was in 1993 in C++. Is there a API call to access the scroll bar LargeChange in a textbox? There must be someone to can enlighten me. I know that this question is probably lame but could use some help.
    The API function you are seeking is the SetScrollInfo function. However, I have never had any luck with it by changing the nPage argument. It appears as though the value is reset when the TB receives the WM_VSCROLL. There may be a way if dealing with it by handling the WM_VSCROLL message similar to what Edgemeal has shown, but I never investigated it further.

    One thing that is not apparent from your postings is if you are aware that you can scroll page by page just by clicking in the scrollbar area above/below the thumb.
    Last edited by TnTinMN; Jan 5th, 2017 at 09:57 PM. Reason: typos

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2017
    Posts
    4

    Re: Textbox built in vscrollbar, no LargeChange option?

    Thank you TnTinMN, Sitten & Edgemeal,

    The code you provided is a good solution. With 100,00 lines in a text box I didn't realize that it was scrolling a page at a time. This code will be useful If I scroll maybe 100 or 200 lines at a time the text box is 25 lines long, thank you. It's going to take me some time to master VB.NET. My project is for data acquisition from one of my Tektronix instruments that I made a PIC controller to grab the BCD data and send it to my USB hid program. My program is about 60 pages of code so far but so much to learn. I'll search the forum a little better before I post again anything again. Thank again, consider this thread closed.

  8. #8
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,191

    Re: Textbox built in vscrollbar, no LargeChange option?

    Quote Originally Posted by Dosmith54 View Post
    Thank again, consider this thread closed.
    If you look at Thread Tools above your first post, you can mark it Resolved.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width