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
Re: Panel scrollbars don't move when I scroll window via code.
from which methods/order does this run?
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.
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.
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. :(
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
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.
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…
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. :(
Re: Panel scrollbars don't move when I scroll window via code.
Try setting it this way…
Code:
pnlContent.AutoScrollPosition = New Point(0, 360)
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!
Re: Panel scrollbars don't move when I scroll window via code.
Quote:
Originally Posted by
Mugsy323
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!
:thumb:
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. :(
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…
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
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.
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