Form Size

How can you make the size (height) of a form exceed the size of the screen, using a vertical scroll bar to view the entire length of the form?

I've set the size of the form with the "form.height = " statement in the form.load procedure - it doesn't error out, but it also doesn't set the form to the size I want.

I've changed my windows setting to the highest resolution I can get, stretched the form the limits of the screen, saved it, and set my resolution back to normal - I still can't exceed screen height.

I've tried the above plus making the form a MDI child - I can get then get scroll bars and a form as high/long as it was when I was set to the highest resolution, but not the form length I want.

The end results I'm looking for are:
1. A form that, when printed, will fill a 8.5x11 standard sheet of paper.   The best I can get right now at 800x600 resolution is 1/2 page.
2. A form, sized at run time based on the number of data record read from file, that can display all the data lines regardless of screen size.

This one is beating me up. I'm using VB4, but can upgrade it to VB5 if thats an issue.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try setting the borderstyle of the form to 0, then resize the form.

If you need a bordered window you can use APIs to set the width and height to anything you wish.  Windows maintains information regarding each window's sizing properties in a MINMAXINFO data structure.  VB sets the maximum sizing values of this structure to the screen size.  In order to modify this information, the window must be subclassed in order to intercept the WM_MINMAXINFO message. You can then modify the default values.  Here is a code example of how to change the width:

Option Explicit

Private Sub Command1_Click()
'Set the width to 16000 twips
Me.Width = 16000
'Confirm width change
Debug.Print Width
End Sub

Private Sub Form_Load()
' Hook into the message stream.
'Caution: DO NOT pause or break while in IDE
'while the window is subclassed.
glPrevWndProc = fSubClass()
End Sub

Private Sub Form_Unload(Cancel As Integer)
' Stop intercepting messages.
Call pUnSubClass
End Sub

Option Explicit

Public Const GWL_WNDPROC = (-4)
Public Const WM_GETMINMAXINFO = &H24
    x As Long
    y As Long
End Type
    ptReserved As POINTAPI
    ptMaxSize As POINTAPI
    ptMaxPosition As POINTAPI
    ptMinTrackSize As POINTAPI
    ptMaxTrackSize As POINTAPI
End Type
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As Long, _
    ByVal dwNewLong As Long) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
    (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, _
    ByVal Msg As Long, ByVal wParam As Long, _
    ByVal lParam As Long) As Long
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
    hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)

Private mmi As MINMAXINFO
Public glPrevWndProc As Long

Public Sub pUnSubClass()
' Stops the form from intercepting Window's messages
' by resetting the default procedures associated
' with the form.
Call SetWindowLong(Form1.hwnd, GWL_WNDPROC, glPrevWndProc)
End Sub

Public Function pMyWindowProc(ByVal hw As Long, ByVal uMsg As Long, _
    ByVal wParam As Long, ByVal lParam As Long) As Long
' This is the callback procedure used when a message is received
' by this form.  The desired message is processed and all others are
' passed back to the original procedure associated with the form.
    'lParam points to a MINMAXINFO structure
    CopyMemory mmi, ByVal lParam, LenB(mmi)
    'Specify maximum width of 18000 twips
    mmi.ptMaxTrackSize.x = 18000 / Screen.TwipsPerPixelX
    'Copy the modified info back to Windows
    CopyMemory ByVal lParam, mmi, LenB(mmi)
End If

pMyWindowProc = CallWindowProc(glPrevWndProc, hw, uMsg, wParam, lParam)
End Function

Public Function fSubClass() As Long
' Subclass the form by replacing the "normal" procedures associated
' with the form with procedure "pMyWindowProc".
' NOTE: Comment all calls to fSubClass while in IDE.
fSubClass = SetWindowLong(Form1.hwnd, GWL_WNDPROC, AddressOf pMyWindowProc)
End Function
Oops, you will also need to set the info for the height as well in the function pMyWindowProc:

mmi.ptMaxTrackSize.y = 18000 / Screen.TwipsPerPixelX
spraterAuthor Commented:
Thanks for the answer - it obviously took some time work up...but


I have a very limited knowledge of VB and I don't have a clue what you just said!

I did do some searching in the previously answered questions and found what appears to be a simple solution..

Create a picture box and put put my controls in the box, with a vscroll on the form.  This seems to do what I need in every respect but one...the scroll is going in the opposite direction!  If I click the down arrow, the top of the picture moves down, instead of the top of the picture moving up.  I'm using the code below to drive the scroll bar.  How can I reverse the values (to a negative, I guess) so the top of the picture scrolls down when the down button is clicked?

VScroll1.Min = 0 ' Initialize scroll bar.
    VScroll1.Max = 10000
    VScroll1.LargeChange = 1000
    VScroll1.SmallChange = 100
 Picture1.Top = VScroll1.Value
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

spraterAuthor Commented:
I have found my answer to the form length/scroll bar issue at

I still need an answer to the form printing isuue if anyone can help...

I have a form sized to the max height of my screen at 1024x760 rosolution.  At this resolution, the form prints in it's entirety.  At 800x600 resolution, the only part of the form that will print is the portion of the form visible on the screen - about 1/2 page worth.  I need the whole thing to print at the lower resolution.

Your form size may not directly exceed the screen limits.

There is one by-pass however, make the form a MDI child and show it through a MDI form. An MDI Child may exceed the size of the screen, In such a case, the Scroll Bar automatically comes up on the MDI Form.



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
>>Your form size may not directly exceed the screen limits.<<

Yes it can, if you use the code in my previously rejected answer...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.