Results 1 to 17 of 17

Thread: Panel scrollbars don't move when I scroll window via code.

  1. #1

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    112

    Question Panel scrollbars don't move when I scroll window via code.

    Thx for clicking on my question.

    I'm displaying a form in scrollable panel/window. I'm able to force the window to scroll up/down to a desired point (ONCE), but when I do, the scrollbar doesn't move. So the next time I try, the form jumps back to the top. Very annoying.

    Code:
    intFormPos = frmMain.pnlMain.VerticalScroll.Value ' Record starting position
    [...]
    frmMain.pnlMain.VerticalScroll.Value = intFormPos ' Jump back.
    Is there a solution? TIA

  2. #2
    Addicted Member
    Join Date
    Jan 2022
    Posts
    211

    Re: Panel scrollbars don't move when I scroll window via code.

    from which methods/order does this run?

  3. #3

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    112

    Re: Panel scrollbars don't move when I scroll window via code.

    Thx for the reply.

    In this particular instance, it takes place in a "_MouseLeave" instance from a floating preview image.

  4. #4
    Addicted Member
    Join Date
    Jan 2022
    Posts
    211

    Re: Panel scrollbars don't move when I scroll window via code.

    ive not tried moving the position around on a scroll before, but from here it looks like you should be declaring intFormPos as a class member. Also, after the first mouse leave frmMain.pnlMain.VerticalScroll.Value and intFormPos will always be the same value. You will need to set the intFormPos to a desired position in some other way, maybe in the scroll event. Im not sure what behavior youre looking for.

  5. #5

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    112

    Re: Panel scrollbars don't move when I scroll window via code.

    I created a small sample project to demonstrate what's going on:

    I put a form inside a panel. On Load, I try (and fail) to scroll the form. If you click the "Label" halfway down, a popup tells you the current vertical position of the Scrollbar. Close the popup and the form jumps back to the top.

  6. #6
    Addicted Member
    Join Date
    Jan 2022
    Posts
    211

    Re: Panel scrollbars don't move when I scroll window via code.

    One thing I dont do i DL ppls projects.

    Paste the entire class instead

  7. #7

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    112

    Re: Panel scrollbars don't move when I scroll window via code.

    Class for Form1 (an 800x500 form with a Panel object called pnlContent nearly filling the form):

    Code:
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            frmIcons.TopLevel = False       ' Supress error.
            pnlContent.Controls.Add(frmIcons) ' Load frmIcons into Panel.
            frmIcons.Height = 1078
            frmIcons.Show()
            pnlContent.VerticalScroll.Value = 360 ' Should scroll the form but doesn't.
        End Sub
    End Class
    "frmIcons" is a big borderless form (800, 1078) that simply contains two do-nothing buttons, one on top left, the other on bottom right and a big Label dead center. I put a "Click" action on the label to display the current VerticalScroll position:

    Code:
    Public Class frmIcons
        Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
            MsgBox(Form1.pnlContent.VerticalScroll.Value) ' Click label to display VerticalScroll.Value. Form scrolls right back to the top on close.
        End Sub
    End Class
    Should be easy enough to recreate. Thx.
    Last edited by Mugsy323; Aug 13th, 2023 at 01:51 PM.

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Panel scrollbars don't move when I scroll window via code.

    After setting the scroll value, try refreshing either the panel or the vscroll or both…

  9. #9

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    112

    Re: Panel scrollbars don't move when I scroll window via code.

    Refreshing the panel made no difference. And I don't know how to "refresh" the vscroll.

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

    Re: Panel scrollbars don't move when I scroll window via code.

    Try setting it this way…

    Code:
    pnlContent.AutoScrollPosition = New Point(0, 360)

  11. #11

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    112

    Re: Panel scrollbars don't move when I scroll window via code.

    Hmm. That didn't work either but I FOUND A SOLUTION!

    After setting the ".VerticalScroll.Value" I then set ".ScrollControlIntoView(sender)" and it jumps right to the location of the floating preview triggered by my "_MouseLeave" instance. Works great!

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Panel scrollbars don't move when I scroll window via code.

    Quote Originally Posted by Mugsy323 View Post
    Hmm. That didn't work either but I FOUND A SOLUTION!

    After setting the ".VerticalScroll.Value" I then set ".ScrollControlIntoView(sender)" and it jumps right to the location of the floating preview triggered by my "_MouseLeave" instance. Works great!

  13. #13

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    112

    Re: Panel scrollbars don't move when I scroll window via code.

    Crud. Seems I spoke a bit too soon on "it works great."

    At low resolution, it causes the form to repeatedly refresh b/c the form is still jumping to the top (triggering a "MouseLeave") and then repositioning (triggering a "MouseHover"), causing the preview window to repeatedly open/close.

    If only there were a way to stop the form from resetting & jumping to the top on MouseLeave.
    Last edited by Mugsy323; Aug 13th, 2023 at 08:27 PM.

  14. #14
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Panel scrollbars don't move when I scroll window via code.

    You can probably fix that by using different events, or by adding conditionals in the events you’re using. We need to see the full relevant code, i.e. the complete event handler code…

  15. #15
    Addicted Member
    Join Date
    Jan 2022
    Posts
    211

    Re: Panel scrollbars don't move when I scroll window via code.

    Instead of using a form to add into pnlContent try using a UserControl instead

    Also make sure AutoScroll on pnlContent is set to true

  16. #16

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    112

    Re: Panel scrollbars don't move when I scroll window via code.

    I'm not sure what you mean by using a "UserControl" instead of a form.

    AutoScroll already set to True, but "False" didn't work either.

  17. #17
    Addicted Member
    Join Date
    Jan 2022
    Posts
    211

    Re: Panel scrollbars don't move when I scroll window via code.

    in a very generic example:
    Code:
    Public Class FormIcons
        Private Sub FormIcons_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim UC_Icons As New UserControl With {.Dock = DockStyle.Top, .Height = 1000}
    
            With pnlContent
                .AutoScroll = True
                .Controls.Add(UC_Icons)
            End With
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            pnlContent.AutoScrollPosition = New Point(0, 200)
        End Sub
    End Class
    you would likely create the UserControl in the designer though as with the icons

Tags for this Thread

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