Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Aug 21, 1997

Scrollable Viewport for a Picture

It's easy to make a scrollable viewport for a picture in both VB3 VB4. In addition to a picture, you can also use other objects that grow. First, create a new form. Place a picture box on the form, name it "picParent," and resize it. This will be the viewport. Place a picture box inside the other picture box (picParent) and name it "picPICTURE." The value of the Left and Top properties must be zero. This one will contain the picture you want to view. Next, place a vertical scrollbar on the right of the picParent Picture. Name it "vsbPict." This scrollbar should have the same Top and Height values as picParent. Do the same with a horizontal scrollbar. Place it on the bottom of "picParent"-the Left and Width values should be equal to picParent. Name it "hsbPic." In both scrollbars, set the LargeChange property to the height and width of picParent, respectively. Then place this code on the declarations section of Form1. You can also copy this code to the Scroll event:
 
Private Sub hsbPIC_Change()
	picPicture.Left =hsbPIC.Value
End Sub
Private Sub vsbPIC_Change()
	picPicture.Top =vsbPIC.Value
End Sub
Private Sub picPicture_Resize()
	If picPicture.Height > picParent.Height Then
		vsbPIC.Max =picParent.Height - picPicture.Height
	Else
		vsbPIC.Max = 0
	End If
	If picPicture.Width > picParent.Width Then
		hsbPIC.Max =picParent.Width - picPicture.Width
	Else
		hsbPIC.Max =0
	End If
		vsbPIC.Value = 0
		hsbPIC.Value = 0
End Sub
Every time you load a new picture, the scrollbars will adjust to its size. Write the code to load the pictures, and write other code to deal with exceptions to the rules.
Joel Paula
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date