Hi all,
I have some code which populates a flow layout panel with a number of buttons. The number of buttons is completely dynamic (it's based on how many subfolders are in a given Directory.)
What I want to be able to to is use two buttons to scroll up and down the panel, without the use of scrollbars.
I've spent a good few hours looking around trying to find a solution (as well as messing around with the 'verticalscroll' properties of the panel with code, but with no success.
Does anyone have any idea of how to acheive such a thing? As I'm very close to throwing my pc out of the window in a fit of rage and frustration
Thanks
TheMightySpud
Scroll a panel using butttons and not scrollbars
Page 1 of 12 Replies - 4819 Views - Last Post: 22 November 2010 - 04:11 PM
#1
Scroll a panel using butttons and not scrollbars
Posted 18 November 2010 - 04:03 PM
Replies To: Scroll a panel using butttons and not scrollbars
#2
Re: Scroll a panel using butttons and not scrollbars
Posted 18 November 2010 - 04:23 PM
Not sure if this will help you as it only works with AutoScroll set to True but you can do the following:
This will move the scroll up with each press. Of course you would use posY -= 10 in your other button to reverse it.
You may have to check to make sure you don't go below 0 but I'm not sure.
This however, will show the scroll bars in the panel it just lets you use buttons to move it.
Just remember to make the posY variable availabel to both buttons by keeping it at class level.
Dim posY As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Panel1.AutoScrollPosition = New Point(0, posY)
posY += 10
End Sub
This will move the scroll up with each press. Of course you would use posY -= 10 in your other button to reverse it.
You may have to check to make sure you don't go below 0 but I'm not sure.
This however, will show the scroll bars in the panel it just lets you use buttons to move it.
Just remember to make the posY variable availabel to both buttons by keeping it at class level.
This post has been edited by CharlieMay: 18 November 2010 - 04:28 PM
#3
Re: Scroll a panel using butttons and not scrollbars
Posted 22 November 2010 - 04:11 PM
Hi,
Thanks for the response, took a little tinkering (testing limits etc) but I got i working.
for anyone else who's interested
To scroll down
To scroll up
As for the Autoscroll bars being visible, I couldn't figure out how to get rid of them from the form, so I just did a little cheat and used my Back button to cover the scrollbar so it looks as though it's not there (as can be seen in the screenshot I've attached. I've no doubt that there's a more elegant way of doing it, but for the moment, it works, so I'm happy

Again, Thanks for the help
TheMightySpud
Thanks for the response, took a little tinkering (testing limits etc) but I got i working.
for anyone else who's interested
To scroll down
Private Sub btn_ScrollDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If ypos > tvPanel.VerticalScroll.Maximum - 451 Then
ypos = tvPanel.VerticalScroll.Maximum - 450
Else
ypos += 450
tvPanel.AutoScrollPosition = New Point(0, ypos)
End If
End Sub
To scroll up
Private Sub btn_ScrollUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If ypos < 1 Then
ypos = 0
Else
ypos -= 450
tvPanel.AutoScrollPosition = New Point(0, ypos)
End If
End Sub
As for the Autoscroll bars being visible, I couldn't figure out how to get rid of them from the form, so I just did a little cheat and used my Back button to cover the scrollbar so it looks as though it's not there (as can be seen in the screenshot I've attached. I've no doubt that there's a more elegant way of doing it, but for the moment, it works, so I'm happy

Again, Thanks for the help
TheMightySpud
This post has been edited by TheMightySpud: 22 November 2010 - 04:13 PM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|