Results 1 to 24 of 24

Thread: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    This UserControl is a control container, like a PictureBox or a Frame but that can be scrolled.

    It can be useful when the controls we need to display do not fit in the available space.

    Name:  ScrollableContainer_scr.png
Views: 2230
Size:  19.9 KB

    Last update: May 08, 2022

    Download from GitHub.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    How to use it

    To add controls at design time, drag the controls inside it as it is done with any other container.
    The properties VirtualHeight and VirtualWidth determine the size of the virtual space at design time, and the properties VScrollValue and HScrollValue the scroll position.
    Alternatively, you can right click on the control and select "Edit", and the scroll bars will become active at design time. Every time that you add a new control you'll have to select "Edit" again.


    Reference

    Properties:

    Note: the extender's properties are not included here (Top, Left, Visible, Etc.)

    Notation:
    D: available at design time
    R: read only property

    AddingControls: --
    AutoScrollOnFocus: D-
    BackColor: D-
    BorderColor: D-
    BorderStyle: D-
    BottomFreeSpace: D-
    HScrollBar: D-
    HScrollMax: -R
    HScrollValue: D-
    hWnd: -R
    RightFreeSpace: D-
    VirtualHeight: D(not persistable)-
    VirtualWidth: D(not persistable)-
    VScrollBar: D-
    VScrollMax: -R
    VScrollValue: D-
    TopScrollBound D-

    Description

    AddingControls:
    Use this property when you need to add controls to this container at run time. It is to indicate to the ScrollableContainer that you are adding controls, so that the position that you set to the newly added controls (Left and Top) are set correctly in the virtual space of the container.
    Example use:

    Code:
        ScrollableContainer1.AddingControls = True
    
        ' Adding a command button
        Set NewCmd1 = Me.Controls.Add("VB.CommandButton", "NewCommand1")
        Set NewCmd1.Container = ScrollableContainer1
        NewCmd1.Move 1000, 1000
        NewCmd1.Caption = "New command 1"
        NewCmd1.Visible = True
    
        ' Adding another command button
        Set NewCmd2 = Me.Controls.Add("VB.CommandButton", "NewCommand2")
        Set NewCmd2.Container = ScrollableContainer1
        NewCmd2.Move 1600, 1000
        NewCmd2.Caption = "New command 2"
        NewCmd2.Visible = True
    
        ScrollableContainer1.AddingControls = False

    AutoScrollOnFocus:
    Returns or sets a value that determines if when a contained control gets the focus, if the ScrollableContainer will automatically scroll to show the control in case that it is out of the view.
    A control that is out of view can get the focus because the user is navigating with the Tab key, or pressed an accelerator that is set on the control, or there is a SetFocus to that control in the code.

    BackColor:
    Returns or sets the background color.

    BorderColor:
    Returns or sets the color of the border when BorderStyle is set to efnFlat1Pix or efnFlat2Pix.

    BorderStyle:
    Returns or sets a value that determines how the border of the control looks like.

    BottomFreeSpace, RightFreeSpace:
    Returns or sets a value that determines, in scale mode units of the ScrollableContainer's container, the free space that will be left at the bottom or the right of the virtual space (when there is no other control to scroll for).

    HScrollBar, VScrollBar:
    Returns or sets a value that determines the horizontal or vertical scrollbar visibility at run time.

    HScrollMax, VScrollMax:
    Returns a value, in scale mode units of the ScrollableContainer's container, that indicates the maximum value that HScrollValue / VScrollValue can take, corresponding to the scroll bar position's when the scroll box is in its bottom or rightmost position.

    HScrollValue, VScrollValue:
    Returns or sets a value, in scale mode units of the ScrollableContainer's container, that indicates the scroll actual position.
    It can be set at design time to change the scroll position, but the design time value is not saved and at run time it starts with 0 (zero).

    hWnd:
    Returns the Windows handle of the control.

    VirtualHeight, VirtualWidth:
    Returns or sets a value that determines, in scale mode units of the ScrollableContainer's container, the height / width of the virtual space where the controls are located.
    It can be set at design time to change the virtual space height, but the design time value is not saved and the run time value is calculated automatically.

    TopScrollBound:
    Returns or sets a value, in scale mode units of the ScrollableContainer's container, that sets a limit for the Vertical Scroll that the user can set.

    Events:

    HScrollChange, VScrollChange:
    Generated when HScrollValue and VScrollValue change.


    Methods:

    EnsureControlVisible:
    Ensures that the control referenced in the nControl parameter is visible on the container. If it is not, the ScrollableContainer is automatically scrolled in any needed direction to show the control.
    Example use: ScrollableContainer1.EnsureControlVisible Text10

    Update:
    Updates the virtual space dimensions. Usually not necessary to call it because it is done automatically.

  3. #3
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    506

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    Hello,
    in the ide closes the ide does not work, compiled yes.
    a greeting

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    Quote Originally Posted by yokesee View Post
    Hello,
    in the ide closes the ide does not work, compiled yes.
    a greeting
    Can you provide an example (a project) or a better explanation of what you mean?

  5. #5
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    506

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    sorry for my english use translator.
    When I open your project and open Form1 in design mode the ide closes automatically.
    also if I execute it from the ide without opening any design sale closes the ide.
    if I do not open anything and compile it the executable works perfectly.

    summary only works for me compiled

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    Quote Originally Posted by yokesee View Post
    sorry for my english use translator.
    When I open your project and open Form1 in design mode the ide closes automatically.
    also if I execute it from the ide without opening any design sale closes the ide.
    if I do not open anything and compile it the executable works perfectly.

    summary only works for me compiled
    OK, thanks for the explanation.
    It doesn't happen here. It must be something in the subclassing code, I changed the subclassing technique for a self-contained one before posting the project here.
    The problem is that I can't fix something that is working.

    To anyone else that have tried the code, does it crash also or it works?

    What I could do is to try with another subclassing technique...

    Edit: I also tested in another computer, that has Windows XP, and it works without crashing.

  7. #7
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    It works here at design-time w/o problems.

    @yokesee: Do you have SP6 installed? That is Service Pack 6 for VB6.

    cheers,
    </wqw>

  8. #8
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    506

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    can that be the problem, I can not install the sp6 on windows 10
    I do not want to desisntalar it and reinstall any other solution

  9. #9
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    What version of VB and which service pack are you using ?

  10. #10
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    506

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    https://imgur.com/q5UHwMT
    this is the version and tried many options that I have seen online to be able to update but I can not.
    I know that if I uninstall it and install it again it will work but I am afraid of losing many settings and things.
    a greeting

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    Updated. Added support for Line controls.

  12. #12
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    Subclassing takes over his mouse events, and you can do a lot of interesting things. Even create your own shortcuts. In the custom control

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    Updated: Added mouse wheel support for horizontal scrollbar.

  14. #14
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    597

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    Quote Originally Posted by Eduardo- View Post
    Updated: Added mouse wheel support for horizontal scrollbar.
    The Mouse wheel scrolling is infinite in this demo?

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    Quote Originally Posted by DaveDavis View Post
    The Mouse wheel scrolling is infinite in this demo?
    I don't understand the question, if you tested the demo.

    If you didn't check the demo, then the answer is no, it scrolls only where there are controls.

  16. #16
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    597

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    Quote Originally Posted by Eduardo- View Post
    I don't understand the question, if you tested the demo.

    If you didn't check the demo, then the answer is no, it scrolls only where there are controls.
    The Mouse Scrolling is infinite in my test and leaves a blank area on bottom. When I go to top, the top visible control can't go to "Enter data 1" any more...Name:  Screenshot 2022-05-09 085042.png
Views: 871
Size:  13.9 KB

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    I saw that problem a few times. I think I remember that it returned to normal by closing the form and reopening it (or something like that, that reset the state. Maybe you need to close the project and reopen it).
    I also remember that I tried to fix it, but it slipped away.

    Unfortunately I am not being able to make it happen now.
    Yes, it is not perfect, I shared this control that I made for me because I thought it might be useful for others.
    If I could recreate the issue again, I could give it another try.

    But... it has nothing to do with the mouse wheel, and it being infinite.
    It is that the controls inside the container are left moved.

    I strongly recommend to use this control from a compiled ocx. If you are going to use it in standard exes (I did), do not make anything weird, just put the controls inside and handle them by code (instead of design time) as much as possible.

  18. #18

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    As a side note, that has nothing to do with this project directly, I strongly encourage to install SP6 (Visual Basic 6 Service Pack 6).
    Any project that uses an UserControl can crash the IDE otherwise (due to a VB6 bug). Even with no code involved.

    Unless stated otherwise, VB6 SP6 is assumed for all my projects.

  19. #19
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    673

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    xxdoc commented 19 hours ago •
    Option Explicit

    Private Sub Form_Load()
    'Duplicate a bunch of controls:

    Dim I As Integer

    For I = 0 To 100

    If I > 0 Then
    Load lblData(I)
    Load txtData(I)

    With lblData(I)
    .Move lblData(0).Left, lblData(I - 1).Top + lblData(I - 1).Height + 5 * Screen.TwipsPerPixelY
    .Caption = I
    .Visible = True

    End With

    With txtData(I)
    .Move txtData(0).Left, txtData(I - 1).Top + txtData(I - 1).Height + 5 * Screen.TwipsPerPixelY
    .Visible = True

    End With

    End If

    DoEvents
    Next

    ScrollableContainer1.VirtualHeight = txtData(I - 1).Top + txtData(I - 1).Height
    ScrollableContainer1.VScrollBar = vxScrollBarShow
    ScrollableContainer1.HScrollBar = vxScrollBarHide
    End Sub

    IF I change
    ScrollableContainer1.VScrollBar = vxScrollBarShow
    ScrollableContainer1.HScrollBar = vxScrollBarHide
    may be not scrolled

    Problems arise if properties are modified.

  20. #20

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    Quote Originally Posted by xxdoc123 View Post
    ScrollableContainer1.VScrollBar = vxScrollBarShow
    ScrollableContainer1.HScrollBar = vxScrollBarHide
    may be not scrolled

    Problems arise if properties are modified.
    It works for me. Install SP6.

  21. #21
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    673

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    Quote Originally Posted by Eduardo- View Post
    It works for me. Install SP6.
    .Of course I installed SP6 if I drag the control don't change any attributes,will work ok .Of course I installed SP6. If I change some attributes, then the scroll bar cannot be rolled. EXE cannot be rolled. Mine is the home version of Win10 system.

  22. #22

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    Quote Originally Posted by xxdoc123 View Post
    .Of course I installed SP6 if I drag the control don't change any attributes,will work ok .Of course I installed SP6. If I change some attributes, then the scroll bar cannot be rolled. EXE cannot be rolled. Mine is the home version of Win10 system.
    This control works better compiled. Since it is subclassed in the IDE, it can cause issues when not compiled, unfortunately.
    I suggest to put in in an OCX project, compile, and then use it.

    I'll convert it to an OCX project (at some point, maybe later).

    For a quick fix, try closing the IDE and opening the project again.

  23. #23
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    673

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    Quote Originally Posted by eduardo- View Post
    this control works better compiled. Since it is subclassed in the ide, it can cause issues when not compiled, unfortunately.
    I suggest to put in in an ocx project, compile, and then use it.

    I'll convert it to an ocx project (at some point, maybe later).

    For a quick fix, try closing the ide and opening the project again.
    now i test in other pc

    you can see the gif .can not scrolled .
    Attached Files Attached Files

  24. #24

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: [VB6] ScrollableContainer: a container (like a PictureBox) with scroll capability

    Turned it into an OCX project now, so the people can choose between having the issues of using it in source code or having the issues of adding an OCX (it is that you need to add a dependency file).

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