# ScrollBar help

This topic is 2191 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello all.
Currently I'm working on a 2d level editor with xna and winforms and i cant seem to get a formula for a scrollbar to work. At the moment I'm only doing it for 1 axis.

Here are the variables I have:
MapWidth = 100
Scrollbar.Width = 556

And i need to find some way so by the time you reach the end of the scroll bar your at the end of the map.

Here's what i have currently:
 void hsbView_Scroll(object sender, ScrollEventArgs e) { camera.Position = new Vector2(hsbView.Value, 0); if ((camera.Position.X + mapDisplay.Width) / 32 < levels[0].MapWidth) camera.Position = new Vector2(camera.Position.X - 32, 0); } 

##### Share on other sites
Out of my head this should do the trick, however you can only safely call it if the level is actually bigger than the display:

camera.Position.X = ( levels[0].MapWidth * 32 - mapDisplay.Width ) * hsbView.Value / ( hsbView.Maximum - hsbView.Minimum )

##### Share on other sites
Thanks a lot for the help. been scratching my head for ages over that one.

• 10
• 17
• 9
• 14
• 41
×

## Important Information

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!