Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

scrollbar

Posted on 1998-06-15
6
Medium Priority
?
372 Views
Last Modified: 2010-05-03
I have a form, which dynamic changes its size. Sometimes I have two lines of textboxes, and sometimes I have 200 lines of textboxes. Now I want to add a scrollbar to the form, which is always as large as the form itself. I mean, I want to connect the height of the scrollbar to the height of the form, so I can scroll down the form.
0
Comment
Question by:mkdjo
  • 3
  • 3
6 Comments
 
LVL 6

Accepted Solution

by:
clifABB earned 200 total points
ID: 1463313
   What you want to do is place a picturebox on your form.  Size it to the maximum size you will need.  Set the BorderStyle property to
    False.  Move all the controls that are on the form (except the picturebox, of course) to the picturebox.
    Now, add a scrollbar to the form and align it next to the picturebox.

    In the form's resize event, place this code:
    Private Sub Form_Resize()

      VScroll1.Move Me.ScaleWidth - VScroll1.Width, 0, VScroll1.Width, Me.ScaleHeight
      VScroll1.Max = Picture1.Height - Me.ScaleHeight
      If VScroll1.Max < 0 Then
        VScroll1.Max = 0
      End If
      VScroll1.LargeChange = Me.ScaleHeight
      VScroll1.SmallChange = Me.ScaleHeight / 10
    End Sub

    In the scrollbar's change event, place this code:
    Private Sub VScroll1_Change()

      Picture1.Top = VScroll1.Value * -1
    End Sub

    Note:  The above code will work for vertical only (which is what you requested).  To add horizontal scrolling, add a horizontal scrollbar to the
    form.
    Add the following code to the form load event:
    Private Sub Form_Resize()

      VScroll1.Move Me.ScaleWidth - VScroll1.Width, 0, VScroll1.Width, Me.ScaleHeight - HScroll1.Height
      VScroll1.Max = Picture1.Height - Me.ScaleHeight
      If VScroll1.Max < 0 Then
        VScroll1.Max = 0
      End If
      VScroll1.LargeChange = Me.ScaleHeight
      VScroll1.SmallChange = Me.ScaleHeight / 10

      HScroll1.Move 0, Me.ScaleHeight - HScroll1.Height, Me.ScaleWidth - VScroll1.Width, HScroll1.Height
      HScroll1.Max = Picture1.Width - Me.ScaleWidth
      If HScroll1.Max < 0 Then
        HScroll1.Max = 0
      End If
      HScroll1.LargeChange = Me.ScaleWidth
      HScroll1.SmallChange = Me.ScaleWidth / 10
    End Sub

    Add the following code to the vertical scrollbar change event:
    Private Sub VScroll1_Change()

      Picture1.Top = VScroll1.Value * -1
    End Sub

    Add the following code to the horizontal scrollbar change event:
    Private Sub HScroll1_Change()

      Picture1.Left = HScroll1.Value * -1
    End Sub
0
 

Author Comment

by:mkdjo
ID: 1463314
clifABB, this is close to, but not exactly what I want. How can I make  form_resize event? If click on vscroll I get the vscroll_change event, but I don't know how to get the resize event. And I don't know the size of my form, because it changes dynamically. I have locked the question hoping you can specify the answer.
thanks
Martin

0
 
LVL 6

Expert Comment

by:clifABB
ID: 1463315
The resize event changes whenever the form size changes.. Either through the user changing the form's size, or through the form's properties and methods.   Setting Form1.Height, and Form1.Width will fire the Resize event, as well as calling Form1.Move (with the height and/or width parameters).
(of course replace Form1 with the actual name of your form).

Remember, you never want to change the form size to larger than the screen, if you do, you won't be able to scroll it.  This is the purpose of the picturebox.  It can be larger than the form and be able to be scrolled.

Also, if you are creating Textboxes "on the fly", you may have to set the Container property of the textbox to the picture control for the above code to work properly.
0
Independent Software Vendors: 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!

 

Author Comment

by:mkdjo
ID: 1463316
You wrote:
>>Also, if you are creating Textboxes "on the fly", you may have to set the Container >>property of the textbox to the picture
>>       control for the above code to work properly.

How can I do this? I post my code.

Private Sub Form_Load()

    n = 1
     Dim h
   For i = 1 To Form1.PNumber
   Load vorgabe(n) Rem Name of textbox
    vorgabe(n).Top = vorgabe(n - 1).Top + vorgabe(0).Height + 120

    vorgabe(n).Visible = True
    h = vorgabe(n).Top + vorgabe(n).Height + 120
    Height = h + Height - ScaleHeight
    n = n + 1
    Next i

thanks for your help.

0
 
LVL 6

Expert Comment

by:clifABB
ID: 1463317
Right after the line:
    vorgabe(n).Visible = True
use this code:
    set vorgabe(n).Parent = Picture1 'Or whetever you call it

Also, in the line:
    Height = h + Height - ScaleHeight
You should be resetting the picture1.Height, not the form height.
And, since you have turned off the border, you won't need the ScaleHeight:
    Picture1.Height = h + Picture1.Height

0
 

Author Comment

by:mkdjo
ID: 1463318
Thank you, this works. But I don't use the
<< set vorgabe(n).Parent = Picture1 'Or whetever you call it
because my compiler don't know .parent. Resetting the picture1.height is it.

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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
Course of the Month11 days, 22 hours left to enroll

564 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