controlling scrolling in a form programatically?

S

Scott M

Hi,

I am currently trying to write a simple game using vb.net

the form I am working on is 800*600 (this is set as the maximum size)
and autoscroll is set to true. The user moves around the screen by
moving a picturebox (sprite) with the cursor keys.

When the user hits the bottom of the screen I want the screen to
automatically scroll down to keep the picture box in view - The screen
I want to work with is 800*1200 but the window should not resize above
800*600. I would also like to keep a status bar (just a text box) on
the bottom line of the screen (displaying lives etc - this needs to
remain fixed even if the screen scrolls)

Any ideas?

I had a couple of ideas myself - create a "background" picture box
that is 800*1200 (this then displays scroll bars in the form). Then
create a couple of hidden picture boxes, one at the top of the screen
and one at the bottom of the screen. When the user moves the sprite
picture box below the bottom of the form (y>=600) then move focus to
the bottom picture box. And when they move above this (y<600) focus
on the top picture box. In this way the form appears to auto scroll.

However, this means that the status bar gets lost when the screen
scrolls (although I suppose I could move this programatically when the
screen moves). Of course I'll need to trap the user scrolling around
the form themselves as well.

Also heard about mdi forms (never used them though) would I be able to
have the scrolling form as a child with the status bar as a parent?

Finally, how do you programatically scroll a form - I couldn't find
any obvious commands like scrollwindow(x,y)?

thanks in advance

Scott M.
 
S

Steve McLellan

If you handle the scrolling yourself it'd be easy - just build a big
picturebox, put a vertical scrollbar by the side of it and handle the scroll
events. You can then wait until you know the sprite is at the bottom, and
then force the scrollbar to do its stuff. Autoscrolling's great but can't
always be applied to every situation because you don't have full control of
it.

Good luck!

Steve
 
S

Scott M

Hi Steve,

thanks for that, but do you have some code samples to get me started?

or explain to me how I "handle the scroll events"

regards,

Scott M.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top