|
-
Nov 23rd, 2006, 05:31 PM
#1
Thread Starter
Fanatic Member
Scroll Picturebox with resizable form.
I'd just like to post this in case it helps anyone. Found this on microsoft's website and it does just what I wanted.
It adds horizontal and vertical scrollsbars to a picturebox (picture1) if the picturebox is larger than the form or when the form is resized to a size smaller than the picturebox. Reckon it might even be worthy of the codebank.
1. Start a new project in Visual Basic. Form1 is created by default.
2. Add a horizontal scroll bar control and a vertical scroll bar control to Form1. (The size doesn't matter because the program automatically sizes the scroll bars in the Form Resize event code.)
3. Add a picture box control to Form1.
4. Add the following code to the Form
VB Code:
Sub Form_Resize()
On Error Resume Next
' Position the scroll bars:
HScroll1.Left = 0
VScroll1.Top = 0
If Picture1.Width > ScaleWidth Then
HScroll1.Top = ScaleHeight - HScroll1.Height
Else
HScroll1.Top = ScaleHeight
End If
If Picture1.Height > HScroll1.Top Then
VScroll1.Left = ScaleWidth - VScroll1.Width
If Picture1.Width > VScroll1.Left Then
HScroll1.Top = ScaleHeight - HScroll1.Height
End If
Else
VScroll1.Left = ScaleWidth
End If
HScroll1.Width = ScaleWidth
If HScroll1.Top > 0 Then VScroll1.Height = HScroll1.Top
' Set the scroll bar ranges
HScroll1.Max = Picture1.Width - VScroll1.Left
VScroll1.Max = Picture1.Height - HScroll1.Top
HScroll1.SmallChange = Picture1.Width / 10
HScroll1.LargeChange = Picture1.Width - HScroll1.Max
VScroll1.SmallChange = Picture1.Height / 10
VScroll1.LargeChange = Picture1.Height - VScroll1.Max
HScroll1.ZOrder 0
VScroll1.ZOrder 0
End Sub
Sub HScroll1_Change()
Picture1.Left = -HScroll1.Value
End Sub
Sub VScroll1_Change()
Picture1.Top = -VScroll1.Value
End Sub
Private Sub HScroll1_GotFocus()
Picture1.SetFocus
End Sub
Private Sub VScroll1_GotFocus()
Picture1.SetFocus
End Sub
Last edited by sgrya1; Dec 5th, 2006 at 02:36 AM.
-
Nov 23rd, 2006, 05:38 PM
#2
Re: Scroll Picturebox with resizable form.
You should post those kind of things into the CodeBank... anyways, i'm sure mod will move it for you
-
Nov 23rd, 2006, 05:42 PM
#3
Thread Starter
Fanatic Member
Re: Scroll Picturebox with resizable form.
I'm a rookie and don't know my place. Do think it should be there though.
Any suggestions for adding wheelmouse scrolldown?
And if anyone has a chance to look over it and correct it, the slider size isn't quite right with respect to the amount it should scroll.
Last edited by sgrya1; Nov 23rd, 2006 at 05:48 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|