Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

scrollbar

Posted on 1998-06-15
6
Medium Priority
?
370 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
[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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…
Suggested Courses

610 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