Results 1 to 12 of 12

Thread: Scrollbar in controls with API

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    24

    Question Scrollbar in controls with API

    Hello everyone.

    I want to load multiple textbox at run-time in a form. The problem is that after many loading of textbox (going from the top to bottom), many textbox are hidden because the form is too small...

    I need a scroll bar on my form and I was wondering if there was any way to do it with the windows API. If there is a way, will it also be easy to ajust the maximum scroll on that scroll bar (because may be I would load more textbox in my form).

    If it's not possible to do it for a form, is it possible to do it for a picture box, or some container control ? Thank you very much for your times. This forum is very handy and all of you people are really nice!

    Dan

  2. #2
    Fanatic Member
    Join Date
    Sep 2000
    Location
    Over There
    Posts
    522
    I don't know of an api way to do it, but you could just put a scroll bar on the form, and when its clicked, move all the text boxes top property up or down to similiate the scroll.
    It Never Fails. Everytime I try to make a program idiot proof, the world makes a better idiot.

  3. #3
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    If you subclass your form and change the window style to have WS_HSCROLL and WS_VSCROLL set then your from will show scrollbars...I have wrapped this functionality in the EventVB.dll which you could use to make your form scroll as per example 4 on this page e.g.:

    VB Code:
    1. Option Explicit
    2.  
    3. '\\ EventVB event sink classes, declared WithEvents
    4. Private WithEvents apiLink As EventVB.APIFunctions
    5. Private WithEvents apiWnd As EventVB.ApiWindow
    6.  
    7. Private Sub Form_Load()
    8.  
    9. '\\ Initiate the EventVB link
    10.   Set apiLink = New EventVB.APIFunctions
    11.  
    12. '\\ Start subclassing this window
    13.   Set apiWnd = New EventVB.ApiWindow
    14.   apiWnd.hWnd = Me.hWnd
    15.  
    16. With apiWnd
    17.   .VirtualHeight = 300
    18.   .VirtualWidth = 300
    19.   .ScrollBars = vbBoth
    20.   .AutoScroll = True
    21. End With
    22.  
    23.   apiLink.SubclassedWindows.Add apiWnd
    24.  
    25. End Sub

    Hope this helps,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    24

    Talking Thankx, but one more question

    Wow! That's great! Thankx a lot!

    Now how do change the max value of this scrollbar after the form is loaded...?

    Thanks again for your help.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    24

    another question

    Hi, I used the EventVB.dll and the scroll is working well and everything until I decide to resize the window or maximize it...

    Do you know why?

  6. #6
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    (a) Change VirtualHeight and VirtualWidth to reflect the size (in pixels) of your scrollable area. For example if you set them to 1280 and 960 and your secreen is 640 x 480 then the scrollable area should be 2 times as big as the maximised window.
    (b) Change VirtualPageHeight and VirtualPageWidth to set the large change amount (again in pixels) of the scrollbars
    (c) What is happening after you maximise the form?

    Thanks in advance,
    D
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    24

    Talking Thanks again for your help

    Well, I think my computer was out of memory and that was why the scrolling wasn't working anymore after I maximed the window. (I was able to move the scroll button but nothing would move in my form). But now, it's working and thanks to you!

    Now it seems like your EventVB.dll has many useful and interesting functions. Is there any documentation for that dll. May be I can find some other useful functions to use for my application. Thank you!

  8. #8
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    You can download the compiled help file from here - note that (as always) this documentation lags a little behind the development....
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    24
    Here is the code in my Form_onLoad(). The thing is, I tried changing the virtualHeight, virtualWidth and VirtualPageHeight value with many values and nothing changes in my form. It seems like I can scroll like 3-4 times my scroll... Do you have any idea where could be the problem ? Thanks in advance.
    ---
    '\\ Initiate the EventVB link
    Set apiLink = New EventVB.APIFunctions

    '\\ Start subclassing this window
    Set apiWnd = New EventVB.ApiWindow
    apiWnd.hWnd = Me.hWnd

    With apiWnd
    .VirtualHeight = 5
    .VirtualWidth = 5
    .VirtualPageHeight = 5
    .ScrollBars = vbVertical
    .AutoScroll = True
    End With

    apiLink.SubclassedWindows.Add apiWnd
    ---

  10. #10
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    To make your scrollbar max = 5 pages use:

    VB Code:
    1. Option Explicit
    2.  
    3. Dim WithEvents apiLink As EventVB.APIFunctions
    4. Dim WithEvents apiWnd As EventVB.ApiWindow
    5.  
    6. Private Sub Form_Load()
    7.  
    8. '\\ Initiate the EventVB link
    9. Set apiLink = New EventVB.APIFunctions
    10.  
    11. '\\ Start subclassing this window
    12. Set apiWnd = New EventVB.ApiWindow
    13. apiWnd.hWnd = Me.hWnd
    14.  
    15. With apiWnd
    16.     .VirtualHeight = .Height * 5
    17.     .VirtualWidth = .Width
    18.     .VirtualPageHeight = .Height
    19.     .ScrollBars = vbVertical
    20.     .AutoScroll = True
    21. End With
    22.  
    23. apiLink.SubclassedWindows.Add apiWnd
    24.  
    25. End Sub
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    24

    hmm..

    Well it still does'nt work. I made a debug trace on the application and it seems like when I do : .VirtualHeight = .Height * 5, the value of .VirtualHeight do not change on the next line code! As if it was readonly (but if so, an error msgbox should appear no?).

    I also tried to put a label in the form and the label did not scroll at all. I don't understand because the textbox and picturebox are scrolling.... but not a label... it this normal?

    Thank you again for your time.

  12. #12
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    Labels, shapes and image controls are so-called lightweight controls which do not have a window of their own and therefore cannot be moved by the API..instead you will need to put code in the ApiWindow.VerticalScroll event e.g.:

    VB Code:
    1. Private Sub apiWnd_VerticalScroll(ByVal Message As EventVB.enScrollMessages, Position As Long, Cancel As Boolean)
    2.  
    3. Dim ctThis As Control
    4.  
    5. For Each ctThis In Controls
    6.     If ctThis.Container.hWnd = apiWnd.hWnd Then
    7.         If TypeOf ctThis Is Label Or TypeOf ctThis Is Image Then
    8.             ctThis.Top = ctThis.Top - (Screen.TwipsPerPixelY * Position)
    9.         End If
    10.     End If
    11. Next
    12.  
    13. End Sub
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

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