Controls Exceeding Form Size - VScroll

Posted on 2002-07-18
Last Modified: 2012-05-04
Hi, I'm using VB 6.0. Win 98 platform. resolution 800*600
At design time, I'd want to place my controls over a frame in a sstab.

Then, put in a Vscroll to allow user to scroll thru the frame in the SSTab.

both the frame & SSTab size are fixed.

ok, my problem arise when I can't place in those controls at design time... I wouldn't want to use coding to put it into a text file, save it as form & add it into my project later... this is too cumbersome.. any clue?

Question by:mah5696
  • 4
  • 3
  • 3
  • +2

Expert Comment

Comment Utility
Can u elaborate it a little.
What problem r u facing in placing the control in a frame in sstab during the design time.

BTW following is the link if you r facing a problem in resizing controls in SSTab when the form is resized.;EN-US;q187562

Author Comment

Comment Utility
nop, it's not problem for resizing...
I plan to put in a lot of controls onto the a frame, the frame sits inside a SSTab, the SStab is on a form.

I'll fix the size of the form, fix the size of the SSTab, & the size of the Frame.

inside my frame, I'll put in all my controls like textboxes, labels, etc..... together with 1 Vscroll.

ok, show me how u manage to put all the textboxes in the "can't see side" of the frame..

Got me?

Expert Comment

Comment Utility

Author Comment

Comment Utility
any solution since u can get me? :D

basically, I want a scroll in a SSTab...

I can do that by pre-defined those controls position in the code. I dun want this. I'd prefer to do it at design time. Any clue?

Expert Comment

Comment Utility
u wanna stuff many controls in a limited area and u don't want to increase the size of the form, U wanna do it i design time.

righto ?

well never done it, need some r&d like you....
LVL 17

Expert Comment

Comment Utility
So here is what you do:

Place a picture box within the frame and place all of your controls within the picture box.

It would be better to use a picture box instead of a frame as the picture box provides you with a scalewidth, but you can use a frame if you want to.

In this example VS is your vscroll control.
FR is your frame control, or Picture box.
picVP is your picture box within the frame.

When you place the controls you wish to scroll within VP you set the height of VP so that all controls are exposed.
You will have to slide VP up/down while you place all of the controls within the frame/picturebox.

In your form resize event:

'Note if FR is a picture box use FR.ScaleWidth
VisibleWindowSize = FR.height ' set the size of the visibile

' now set the size of the max value of the VS
VS.Max = picVP.Height - VisibleWindowSize
VS.Mon = 0
VS.LargeMove = FR.Height - 255 ' control size of page down
VS.SmallMove = 340 ' About the isze of a text box

'Note if FR is a picture box use FR.ScaleWidth
picVP.Move 0,0, FR.Width ' Move to the top of the frame

VS.Value = 0

In the VScroll Change event:

Sub VS_Change()
VS_Scroll ' simply fire the scroll event
End Sub

Sub VS_Scroll()

' And now for the hard bit
' slide picVP within the frame
' because VS.Min/VS.Max will not let the VS scroll to low/heigh
' this is quite simple.

picVP.Top = -VS.Value ' and its that simple

End Sub
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

LVL 17

Expert Comment

Comment Utility


' Make picVP as flat control at design time but leave
' the borderstyle so you can see the dimensions
' when placing you controls.
' also make a different color to your frame so you can see
' where you are.

' so at run time for best results
picVP.BorderStyle = 0
picVP.BackColor = FR.BackColor

etc.... Hope this helps

Expert Comment

Comment Utility
I am assuming that the creation of the controls are not the actual issue. If I am mistaken please let me know.

I think what you are asking is once the form has the controls on it, how do you get them into the frame and get them to scroll at the same rate as the others...

Try this experiment...

Paste this code into a text file and name it Scroller.frm

Open this new form (the text file) in VB and run the program.

Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3705
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   3705
   StartUpPosition =   3  'Windows Default
   Begin VB.PictureBox BoxFrame
      Height          =   2535
      Left            =   180
      ScaleHeight     =   2475
      ScaleWidth      =   3255
      TabIndex        =   1
      Top             =   420
      Width           =   3315
      Begin VB.PictureBox Box
         Height          =   2475
         Left            =   0
         ScaleHeight     =   2415
         ScaleWidth      =   2955
         TabIndex        =   3
         Top             =   0
         Width           =   3015
         Begin VB.CheckBox Check1
            Caption         =   "Check"
            Height          =   255
            Index           =   0
            Left            =   60
            TabIndex        =   5
            Top             =   120
            Width           =   795
         Begin VB.TextBox Text1
            Height          =   315
            Index           =   0
            Left            =   1080
            TabIndex        =   4
            Text            =   "Text1"
            Top             =   120
            Width           =   1695
      Begin VB.VScrollBar BoxScroller
         Height          =   2475
         Left            =   3000
         TabIndex        =   2
         Top             =   0
         Width           =   255
   Begin VB.Frame Frame1
      Caption         =   "Frame1"
      Height          =   2955
      Left            =   60
      TabIndex        =   0
      Top             =   120
      Width           =   3555
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Private Sub BoxScroller_Change()
    Box.Top = 0 - BoxScroller.Value
End Sub

Private Sub BoxScroller_Scroll()
End Sub

Private Sub Form_Load()
    Dim x As Integer
    ' Hide the frames on the picture boxes
    BoxFrame.BorderStyle = 0
    Box.BorderStyle = 0
    ' Load the controls
    For x = 1 To 50
        Load Text1(x)
        SetParent Text1(x).hWnd, Box.hWnd
        Text1(x).Move Text1(0).Left, Text1(x - 1).Top + 2 * Text1(x).Height
        Text1(x).Visible = True
        Load Check1(x)
        SetParent Check1(x).hWnd, Box.hWnd
        Check1(x).Move Check1(0).Left, Text1(x).Top
        Check1(x).Visible = True
    Next x
    ' Use the height of the last control to figure out the
    ' picture box size and scroller settings.
    Box.Height = Text1(50).Top + 2 * Text1(50).Height
    BoxScroller.Max = Box.Height
    BoxScroller.SmallChange = 10 * Screen.TwipsPerPixelY
    BoxScroller.LargeChange = 10 * BoxScroller.SmallChange
    BoxScroller.Value = 0
End Sub


Author Comment

Comment Utility
guys, preferable without any coding.. just provide me the way how to place all those controls while I can't see them in actual.... thanks.
LVL 17

Expert Comment

Comment Utility
Best way is to generate the controls at run-time and have the form load move all the controls to their correct location.

There are other ways:

Create a picture box Array.

In the topleft corner of each box place an invisible lable like:
(0), (1), (2)

Move your controls onto the picture boxes. Using the send to back you can neatly stack your picture boxes with the top left just showing ad the main part of the box hidden within the right side of the frame. When you want to work on one part you slide it out, like getting a card out of a pack. Work on it, then slide it back.

At run time your form load just stacks the picture boxes so that they look like one continuous picbox.

At design time you make sure each picture box has a border. At run time form_load you set the bordstyle=0.


Accepted Solution

ianouii earned 200 total points
Comment Utility
Hi, I think what u want can be done in such a way.

1) place a form
2) place a ssTab on the form
3) place a frame onto the ssTab exactly same size as the ssTab
4) place the Vscroll on the ssTab
5) place another frame on the 1st frame.
6) ok, place all your controls on the 2nd frame.
7) when you fix the size of the form, wanting to put more controls onto the ssTab, just drag the 2nd frame to be bigger. U can push it up from the form & resize.
8) Max resize of the frame is limited. u'd have to use the property box of the frame to make it big. then, push up the frame, add all your controls down within.
9) after u've completed all your controls, nicely put back your 2nd frame back to normal (dun resize), just put the top same as the 1st frame.

good luck.

Author Comment

Comment Utility
This is what I wanted.... thanks.. though it makes my life difficult of pulling up & down.. anyway, it solves my prob.

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 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

10 Experts available now in Live!

Get 1:1 Help Now