Solved

how to scroll a picture box

Posted on 1998-11-16
5
381 Views
Last Modified: 2010-04-30
I have a form that is set to maxamised. I have a picture box on this form. But the bitmap I put into this picture box is bigger than the form. I would like scroll bars to automaticley appear on the picturebox if it is bigger then the form. Really all I need to know is how to put the scroll bars on and have the picture scroll. Thanks
0
Comment
Question by:rpg_rpg
  • 2
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
waty earned 100 total points
ID: 1445037
1) You have to add 2 scroll bars.
2) Embed you picturebox ccontaining the BMP to view into another picture box.
3) Add code behind your scrollbar to scroll you picturebox winthin the container.

If you need further comments, don't hesitate to contact me

0
 
LVL 2

Expert Comment

by:schild
ID: 1445038
There is now automatic scrolling control, because no one can know what do you mean by scroling, one might want to scroll row by row, in another application you want to scroll a row of icons or bitmaps, and it can be big picture or small.

As you know it can be done, so reading the MSDN's articale will give you more then a hint how to scroll as you wish

****************************************

How to Scroll a Form When VB Forms Are Limited to Screen Size
Last reviewed: July 19, 1996
Article ID: Q109741
The information in this article applies to:
  Professional and Enterprise Editions of Microsoft Visual Basic, 16-bit only, for Windows, version 4.0
  Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0
SUMMARY
A Visual Basic form cannot be sized larger than the screen. This article explains how to scroll the contents of a form to enlarge the usable area of a form.
The sample program below works by scrolling a picture box control which is larger than the form and contains attached controls. When the picture box scrolls, all the attached controls scroll together.
MORE INFORMATION
Step-by-Step Example
NOTE: This technique will not work on any version of Windows NT if any of the Visual Basic lightweight controls (for example, Label Control) are children of the scrolling control and positioned outside of the screen's viewing area. This is due to the way that Windows NT handles drawing to nonlogical areas of the screen. To work around the problem, do not use lightweight controls as children of the scrolling control.
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. Draw a text box control inside the upper-left corner of the picture box such that when the picture box moves, the text box moves with it.
Select the Text1 box and press the F4 key to display the Properties window. Set the Text1 Index property to 0, which is required at design time to make an array of text controls.
You can also enhance this sample program by placing more controls into the picture box. When the picture box scrolls, all the controls scroll.
4. Add the following code to the Form Load event:
      Sub Form_Load ()
         ' Make the picture box bigger than the form:
         Picture1.Move 0, 0, 1.4 * ScaleWidth, 1.2 * ScaleHeight ' Place
            some sample controls in the picture box:
         Dim i As Integer
         For i = 1 To 20
            Load Text1(i)
            Text1(i).Visible = True
            Text1(i).Left = i * Picture1.Height / 20
            Text1(i).Top = Text1(i).Left
         Next
      End Sub
5. Add the following code to the Form Resize event:
      Sub Form_Resize ()
         ' 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 = Abs(hscroll1.Max \ 16) + 1
         hscroll1.LargeChange = Abs(hscroll1.Max \ 4) + 1
         vscroll1.SmallChange = Abs(vscroll1.Max \ 16) + 1
         vscroll1.LargeChange = Abs(vscroll1.Max \ 4) + 1
         hscroll1.ZOrder 0
         vscroll1.ZOrder 0
      End Sub
6. Add the following code to the HScroll1 Change event:
      Sub HScroll1_Change ()
         Picture1.Left = -HScroll1.Value
      End Sub
7. Add the following code to the VScroll1 Change event:
      Sub VScroll1_Change ()
         Picture1.Top = -VScroll1.Value
      End Sub
8. Start the program (or press the F5 key). Click the scroll bars to scroll the form. Close the form to end the program.




Additional reference words: 3.00 4.00 vb416
KBCategory: kbprg kbcode
KBSubcategory: PrgOther


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
Last reviewed: July 19, 1996
)1997 Microsoft Corporation. All rights reserved. Legal Notices.



Good Luck
Schild
0
 
LVL 2

Expert Comment

by:schild
ID: 1445039
waty

you gotcha me this time :)

If only I will learn to send a short message and then ... :)

just kiding
0
 
LVL 14

Expert Comment

by:waty
ID: 1445040
schild, sometime I do long message, sometime short messages are enough. I think my solution is good enough. rpg_rpg could implement it easily. If not, I can post code.

NB : I do this way in my Print Preview OCX and it works versy well.
0
 

Author Comment

by:rpg_rpg
ID: 1445041
This is a good enough answer for me! Thanks a bunch!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now