AllAPI Network - The KPD-Team

 
Allapi Network
 API-Guide
 ApiViewer

 API List

 
API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
 
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
 
This Site
 Search Engine
 Contact Form
 

Donate to AllAPI.net

Using Scrollbars with Pictureboxes

Many programmers have problems with pictureboxes and scrollbars. Here's a solution for that problem:

1. Add to Form1: two pictureboxes (Picture1, Picture2) and one vertical scrollbar (VScroll1). The positions doesn't matter, the objects are positioned automatically by the program. There's only one property that must be set at designtime: AutoRedraw = True of Picture2 (that's very important)!

2. Add following code to Form1

Private Sub Form_Activate()

'Clip image of picture2 to picture1
ScrollPic Picture2, Picture1, VScroll1

End Sub

Private Sub Form_Load()

'Set the properties and positions of the objects
With Me
.Height = 5000
.Width = 6500
End With

With VScroll1
.Left = 3200
.Top = 200
.Height = 1000
End With

With Picture1
.Left = 200
.Top = 200
.Width = 3000
.Height = 1000
End With

'AutoRedraw must be set to True!!!
With Picture2
.Left = 200
.Top = 1500
.Width = 3000
.Height = 2500
.Visible = False
End With

'Variables needed
TwipsX = Screen.TwipsPerPixelX
TwipsY = Screen.TwipsPerPixelY
DestPicx = Picture2.Width / TwipsX
DestPicY = Picture2.Height / TwipsY
VScroll1.Max = Picture2.Height / TwipsY _
- Picture1.Height / TwipsY

'Print A to L on Picture2
Dim i As Integer

For i = 0 To 11
Picture2.Print Chr$(65 + i)
Next i

End Sub


Private Sub VScroll1_Change()

ScrollPic Picture2, Picture1, VScroll1

End Sub


Private Sub VScroll1_Scroll()

ScrollPic Picture2, Picture1, VScroll1

End Sub

3. Add a module with following code:

Declare Function BitBlt Lib "gdi32" _
(ByVal hDestDC As Long, ByVal x As
Long, _
ByVal y As
Long, ByVal nWidth As Long, _
ByVal nHeight As
Long, ByVal _
hSrcDC As
Long, ByVal xSrc As Long, _
ByVal ySrc As
Long, ByVal dwRop As _
Long) As
Long


Public Const SRCCOPY = &HCC0020
Public Const SRCAND = &H8800C6
Public Const SRCINVERT = &H660046

Public TwipsX As Long
Public TwipsY As Long
Public DestPicx As Long
Public DestPicY As Long

Public Sub ScrollPic(SourcePic As Object, _
DestPic As Object, Scroll As Object)

BitBlt DestPic.hDC, 0&, 0&, DestPicx, DestPicY, _
SourcePic.hDC, 0&, Scroll.Value, SRCCOPY

End Sub

 

 


Copyright © 1998-2007, The Mentalis.org Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at http://allapi.mentalis.org/