Solved

scrollbar

Posted on 1998-06-15
6
338 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 50 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

743 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

13 Experts available now in Live!

Get 1:1 Help Now