|
-
Nov 26th, 2000, 03:22 PM
#1
Thread Starter
New Member
How can I get a form to scroll like a text box does? For example, the focus of the form is 0,0 to 500,500. How would I make it 100,100 to 600,600? Thanks
-
Nov 26th, 2000, 05:31 PM
#2
Code:
Dim VPos As Integer
Dim HPos As Integer
Private Sub Form_Load()
'Change the following numbers to the Full height and width of your Form
intFullHeight = 8000
intFullWidth = 8000
'This is the how much of your Form is displayed
intDisplayHeight = Me.Height
intDisplayWidth = Me.Width
With VScroll1
.Height = Me.ScaleHeight
.Min = 0
.Max = intFullHeight - intDisplayHeight
.SmallChange = Screen.TwipsPerPixelX * 10
.LargeChange = .SmallChange
End With
With HScroll1
.Width = Me.ScaleWidth
.Min = 0
.Max = intFullWidth - intDisplayWidth
.SmallChange = Screen.TwipsPerPixelX * 10
.LargeChange = .SmallChange
End With
End Sub
Sub ScrollForm(Direction As Byte)
Dim CTL As Control
'Scroll Vertically
If Direction = 0 Then
For Each CTL In Me.Controls
'Make sure it's not a ScrollBar
If Not (TypeOf CTL Is VScrollBar) And Not (TypeOf CTL Is HScrollBar) Then
'If it's a Line then
If TypeOf CTL Is Line Then
CTL.Y1 = CTL.Y1 + VPos - VScroll1.Value
CTL.Y2 = CTL.Y2 + VPos - VScroll1.Value
Else
CTL.Top = CTL.Top + VPos - VScroll1.Value
End If
End If
Next
VPos = VScroll1.Value
Else
'Scroll Horizontally
For Each CTL In Me.Controls
'Make sure it's not a ScrollBar
If Not (TypeOf CTL Is VScrollBar) And Not (TypeOf CTL Is HScrollBar) Then
'If it's a Line then
If TypeOf CTL Is Line Then
CTL.X1 = CTL.X1 + HPos - HScroll1.Value
CTL.X2 = CTL.X2 + HPos - HScroll1.Value
Else
CTL.Left = CTL.Left + HPos - HScroll1.Value
End If
End If
Next
HPos = HScroll1.Value
End If
End Sub
Private Sub HScroll1_Change()
ScrollForm 1
End Sub
Private Sub HScroll1_Scroll()
ScrollForm 1
End Sub
Private Sub VScroll1_Change()
ScrollForm 0
End Sub
Private Sub VScroll1_Scroll()
ScrollForm 0
End Sub
-
Nov 26th, 2000, 06:10 PM
#3
Thread Starter
New Member
Scrolling the form
Wow! This is JUST what I needed! However, could you do one tiny more favor for me? I really do not understand how this code works, making it very difficult for me to use. Would it be possible to set it up in a code module with two sub-rounties vmove and hmove? That would be incredible if you could, if you cannot thanks aways!
-
Nov 26th, 2000, 06:31 PM
#4
Sure.
Add to a Module.
Code:
Public VPos As Integer
Public HPos As Integer
Public intDisplayWidth As Integer
Public intDisplayHeight As Integer
Public intFullWidth As Integer
Public intFullHeight As Integer
Private Sub ScrollForm(Direction As Byte, frm As Form)
Dim CTL As Control
'Scroll Vertically
If Direction = 0 Then
For Each CTL In frm.Controls
'Make sure it's not a ScrollBar
If Not (TypeOf CTL Is VScrollBar) And Not (TypeOf CTL Is HScrollBar) Then
'If it's a Line then
If TypeOf CTL Is Line Then
CTL.Y1 = CTL.Y1 + VPos - frm.VScroll1.Value
CTL.Y2 = CTL.Y2 + VPos - frm.VScroll1.Value
Else
CTL.Top = CTL.Top + VPos - frm.VScroll1.Value
End If
End If
Next
VPos = frm.VScroll1.Value
Else
'Scroll Horizontally
For Each CTL In frm.Controls
'Make sure it's not a ScrollBar
If Not (TypeOf CTL Is VScrollBar) And Not (TypeOf CTL Is HScrollBar) Then
'If it's a Line then
If TypeOf CTL Is Line Then
CTL.X1 = CTL.X1 + HPos - frm.HScroll1.Value
CTL.X2 = CTL.X2 + HPos - frm.HScroll1.Value
Else
CTL.Left = CTL.Left + HPos - frm.HScroll1.Value
End If
End If
Next
HPos = frm.HScroll1.Value
End If
End Sub
Sub hMove(frm As Form)
ScrollForm 1, frm
End Sub
Sub VMove(frm As Form)
ScrollForm 0, frm
End Sub
Add to a Form with HScroll1 and VScroll1
Code:
Private Sub Form_Load()
'Change the following numbers to the Full height and width of your Form
intFullHeight = 8000
intFullWidth = 10000
'This is the how much of your Form is displayed
intDisplayHeight = Me.Height
intDisplayWidth = Me.Width
With VScroll1
.Height = Me.ScaleHeight
.Min = 0
.Max = intFullHeight - intDisplayHeight
.SmallChange = Screen.TwipsPerPixelX * 10
.LargeChange = .SmallChange
End With
With HScroll1
.Width = Me.ScaleWidth
.Min = 0
.Max = intFullWidth - intDisplayWidth
.SmallChange = Screen.TwipsPerPixelX * 10
.LargeChange = .SmallChange
End With
End Sub
Private Sub HScroll1_Change()
hMove Me 'Move horizontally
End Sub
Private Sub HScroll1_Scroll()
hMove Me 'Move horizontally
End Sub
Private Sub VScroll1_Change()
VMove Me 'Move vertically
End Sub
Private Sub VScroll1_Scroll()
VMove Me 'Move vertically
End Sub
This uses hMove to move horizontally and VMove to move vertically.
-
Nov 26th, 2000, 06:36 PM
#5
Thread Starter
New Member
Sorry to both you once again, but I have another question. When I use this, it does this it does not scroll the background on the form. Also, how can I go backwards? When I click up on the vscroll bar, it goes the same way as if I clicked down. Same with the hscroll bar. Thanks again.
-
Nov 26th, 2000, 06:56 PM
#6
The background doesn't move because this method uses a loop to loop through each control and move them.
-
Nov 26th, 2000, 07:01 PM
#7
Thread Starter
New Member
I see... well than is there a way to actually scroll the form and not just all the objects on the form? Thanks.
-
Nov 27th, 2000, 06:25 AM
#8
PowerPoster
You could use a picturebox as parent of all controls and move this box, would scroll all controls and the background picture
-
Nov 27th, 2000, 04:46 PM
#9
Hyperactive Member
Meagatron, your code only accounts for if there is a line on the form right? It doesn't scroll a command button will it?
Matt 
-
Nov 28th, 2000, 10:36 AM
#10
Frenzied Member
Hey Do you see the else after the if asking if it's a line?
That makes other controls like Commandbuttons move, too.
Nice code Megatron!
Sanity is a full time job
Puh das war harter Stoff!
-
Nov 28th, 2000, 03:52 PM
#11
Originally posted by MPrestonf12
Meagatron, your code only accounts for if there is a line on the form right? It doesn't scroll a command button will it?
/\/\isanThr0p is correct. It will scroll regardless of what control is on there. Read the comments and it will direct you.
-
Dec 3rd, 2000, 05:32 AM
#12
Fanatic Member
Can't we use the API ScrollWindowEx?
I'm not sure how to use it...
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
|