Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

scolling in a form

Posted on 1999-06-23
4
Medium Priority
?
193 Views
Last Modified: 2010-05-02
I have designed a VB form in my PC which screen resolution is 800x600. But when I run the form an an PC which is 640x48, the form cannot be fully display all control.
How do provide a scoll bar in the form so that screen which is lower than 800x600 can scoll the form  .
0
Comment
Question by:adrianmak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Expert Comment

by:KDivad
ID: 1519344
In the form load event, check the screen size. If it's too small, make two scrollbars visible, one along the bottom and one up the right side. Set their Max value to the difference between the screen size you need and the screen size you have. So if it needs 800x600 and you have 640x480, then 800 - 640 will give you 160 (I would divide it by ten and make the bottom scrollbar's Max value be 16) and 600 - 480 gives you 120 (or 12). Then in the Scrollbars' change events, just move all the controls on the form.
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 30 total points
ID: 1519345
I have perfected scrolling forms and here is my solution:
1. Place a picture box on your form.  Now place a second picture box contained within the first and a vertical scroll bar on the form.
2. Place all of your controls onto the second picture box.
3. When runnning the application picture box1 must have its height property below picture box2 in order for scroll bars to appear:  The code is below:

Private Sub Form_Resize()
' **************************************************
' * Author: David Carty
' * The forms height, width, scrollbar height etc.
' * must be resized according to the screen
' * resolution.  This mechanism is implemented
' * within this event.
' **************************************************

' picscroller is the picturebox 1 in the instructions

    picScroller.BorderStyle = 0
    picContainer.BorderStyle = 0

    m_strCurrentProcedure = "VScroll_Change"
    
    picScroller.Height = frmMenu.FormHeights - 1000
    picScroller.Width = Me.Width - VScroll.Width - 100
           
    picContainer.Height = 5600 'This controls the size of the container
    picContainer.Width = Me.Width - 60
       
    VScroll.Top = 0
    VScroll.Left = picScroller.Width + 50
    VScroll.Height = picScroller.Height
       
    VScroll.Max = picContainer.Height - picScroller.Height
    VScroll.Visible = picScroller.Height < picContainer.Height
   
End Sub

Private Sub VScroll_Change()
' **************************************************
' * Make the form appear to scroll relative to the
' * scrollbar.
' **************************************************

    m_strCurrentProcedure = "VScroll_Change"
    picContainer.Top = -VScroll.Value
    
End Sub

or take a look at
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:
 &#61623; Professional and Enterprise Editions of Microsoft Visual Basic, 16-bit only, for Windows, version 4.0
 &#61623; 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
c1997 Microsoft Corporation. All rights reserved. Legal Notices.
0
 
LVL 1

Expert Comment

by:hddp666
ID: 1519346
You might also try scaling all of the controls as percentages of Form.ScaleHeight and Form.ScaleWidth. This code will resize the controls when the form loads, or the user changes the size manually. You might have to use Form1.Height instead, but I think that one includes the title bar at the top. ScaleHeight is the height of the usable area of the form.

Private Sub Form_Resize()

Text1.ScaleHeight = Form1.ScaleHeight * 0.90
Text1.Top = Form1.ScaleHeight * 0.10
Text1.ScaleWidth = Form1.ScaleWidth
Text1.Left = 0

Command1.ScaleHeight = Form1.ScaleHeight * 0.10
Command1.Top = 0
Command1.ScaleWidth = Form1.ScaleWidth * 0.50
Command1.Left = 0

Command2.ScaleHeight = Form1.ScaleHeight * 0.10
Command1.Top = 0
Command1.ScaleWidth = Form1.ScaleWidth * 0.50
Command1.Left = Form1.ScaleWidth * 0.50

End Sub

When the form loads in the smaller screen, all of the controls are proportionally reduced to fit. The size of the fonts you use might also have to be scaled, if the text (as for Command1), runs off the edge of the resized control.


0
 
LVL 1

Expert Comment

by:hddp666
ID: 1519347
Or this, if you want it to work right

Command2.ScaleHeight = Form1.ScaleHeight * 0.10
Command2.Top = 0
Command2.ScaleWidth = Form1.ScaleWidth * 0.50
Command2.Left = Form1.ScaleWidth * 0.50
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

715 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