Archived

This topic is now archived and is closed to further replies.

rapidarp

A Couple Visual Basic Questions

Recommended Posts

I''m working on a small program in Visual Basic. It contains the maps for three small cities. The user can click a button, with the appropriate City''s name on it, and it opens another window with the map of the city. That window has a scroll bar so incase the screen resolution is tool big (or small), the user can scroll. Question #1. - How do I go about getting the scroll bars to work and scroll properly? Question #2. - On the main program window, I have a button where the user can change the program''s color depending on wether or not it''s Day or Night. Daytime colors are standard (grey and blue) and nighttime colors are red (text) and black (background). How can I make it so when the user clicks the button, it switches back and forth between the color settings? Any help would be greatly appreciated. Thanks.

Share this post


Link to post
Share on other sites
Hi,

Question 1: Use the Horizontal and Vertical Scroll bars to alter the top and left of the picture box - I assume you are using a picture box for the picture - and set constraints depending on the size of the picture compared to the screen resolution.

Question 2: Just use form.backcolor = &H0etc (a long value for the color) and the same with the text (forecolor I think - it has been a while since I used VB!)

I assume you are new to programming, it would be better if you said what exactly what you mean by map - is it a picture or a load of shapes on the form?

Good Luck anyway!

Share this post


Link to post
Share on other sites
Well yeah, try what is said in the above, above post! about moving the picture around. I think one of the Win32 API functions will allow you to find the current screen resolution, and if you know the size of the picture that is easy to sort. I am not sure what you mean by the program text - do you mean on the picture or just in general - if it is the latter use backcolor!

Good Luck

Share this post


Link to post
Share on other sites
First off, this program is being developed for the use of my local police officers (whom I volunteer with). The problem I ran into a while back when I first started this program was that the resolution on their laptops (in their patrol cars) was like 600x800 (i think) and that cut off the window that contained the map (picture). I wanted to use scroll bars so when this happens, they can still view all parts of the map.

Is there something I can do to make all the windows conform to their resolution and not get cut off?

Share this post


Link to post
Share on other sites
If you have a picture box and a horizontal and vertical scroll bar on the form, use:

Private Sub Form_Load()
VScroll1.Max = (Form1.ScaleHeight - Picture1.ScaleHeight)
HScroll1.Max = (Form1.ScaleWidth - Picture1.ScaleWidth)
End Sub

Private Sub HScroll1_Change()
Picture1.Left = HScroll1.Value
End Sub

Private Sub VScroll1_Change()
Picture1.Top = VScroll1.Value
End Sub

to move the picture around. You could design the system so the windows are always fixed at a size that suits the computers. That is the most simple way to do it. Then using scroll bars you can always find your way around - it will necessitate their use though - the other ways are much more complex and there doesn''t seem to be the need for that.

Good Luck

Share this post


Link to post
Share on other sites
I used your code and it compiles but then it only lets me view the picture the same size as the picture box. I want be able to scroll through the entire picture within the pic box.

Hope i''m not loosing you.

Share this post


Link to post
Share on other sites
If I think I understand what you mean, try change the AutoSize option of the picture box on the properties menu to true - then the picture box will automatically take the size of the picture.

Erm think that is what you mean!

Hope it works

Share this post


Link to post
Share on other sites
Ok, lemme see if i can explain this....


I loaded my picture into the picture box.
When I scroll (using ur code from above) it doesn''t show the whole picture; just what the size of the picture box shows.

I want to be able to scroll and see the entire picture within the picture box.

lol.....this is hard to explain.


Also, I got everything to change colors when u click the Day/Night button, but how do I get it to change back to normal colors?


I apologize for all the questions. I haven''t used VB in a long time.

Share this post


Link to post
Share on other sites
Hi,

To toggle between day and night globally declare a boolean (in a module) where day is true and night is false. Then use the following to code to toggle between states:

Dim Daynight as Boolean

...

If Daynight = True Then
''Change Color to night colors here
Daynight = False
Else
''Change Color to day colors here
Daynight = True
End If

That should work!

For the colors, put &H00000000& for the color of the text and &H8000000F& for the background color and it should be normal again!

Hope it helps

Share this post


Link to post
Share on other sites
quote:
Original post by Azerform
Dim Daynight as Boolean

If Daynight = True Then
''Change Color to night colors here
Daynight = False
Else
''Change Color to day colors here
Daynight = True
End If



Or even easier:

Daynight = Not Daynight

Share this post


Link to post
Share on other sites
quote:
Original post by rapidarp
Ok, lemme see if i can explain this....

I loaded my picture into the picture box.
When I scroll (using ur code from above) it doesn''t show the whole picture; just what the size of the picture box shows.

I want to be able to scroll and see the entire picture within the picture box.

lol.....this is hard to explain.



You might want to take a look at the BitBlt function. Keep an Image in memory along with a point that represents the top left pixel of the visible portion that is displayed in the PictureBox. When the user scrolls the PictureBox update it with BitBlt.


Share this post


Link to post
Share on other sites