|
-
Aug 12th, 2023, 07:51 PM
#1
Thread Starter
Lively Member
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
-
Aug 12th, 2023, 08:12 PM
#2
Addicted Member
Re: Panel scrollbars don't move when I scroll window via code.
from which methods/order does this run?
-
Aug 12th, 2023, 09:08 PM
#3
Thread Starter
Lively Member
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.
-
Aug 13th, 2023, 07:09 AM
#4
Addicted Member
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.
-
Aug 13th, 2023, 12:26 PM
#5
Thread Starter
Lively Member
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.
-
Aug 13th, 2023, 01:08 PM
#6
Addicted Member
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
-
Aug 13th, 2023, 01:46 PM
#7
Thread Starter
Lively Member
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.
-
Aug 13th, 2023, 03:18 PM
#8
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…
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 13th, 2023, 04:02 PM
#9
Thread Starter
Lively Member
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.
-
Aug 13th, 2023, 04:39 PM
#10
Re: Panel scrollbars don't move when I scroll window via code.
Try setting it this way…
Code:
pnlContent.AutoScrollPosition = New Point(0, 360)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 13th, 2023, 04:58 PM
#11
Thread Starter
Lively Member
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!
-
Aug 13th, 2023, 05:05 PM
#12
Re: Panel scrollbars don't move when I scroll window via code.
 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!
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 13th, 2023, 08:16 PM
#13
Thread Starter
Lively Member
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.
-
Aug 13th, 2023, 09:41 PM
#14
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…
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 14th, 2023, 04:59 AM
#15
Addicted Member
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
-
Aug 14th, 2023, 08:27 AM
#16
Thread Starter
Lively Member
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.
-
Aug 14th, 2023, 09:42 AM
#17
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|