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.

Steve
spraterAsked:
Who is Participating?
 
gajendraConnect With a Mentor Commented:
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.

HTH

Gajendra
0
 
Erick37Commented:
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:

'~~~~~FORM_CODE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
'~~~~~END_FORM_CODE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

'~~~~~MODULE_CODE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Option Explicit

Public Const GWL_WNDPROC = (-4)
Public Const WM_GETMINMAXINFO = &H24
Type POINTAPI
    x As Long
    y As Long
End Type
Type MINMAXINFO
    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.
'
If uMsg = WM_GETMINMAXINFO Then
    '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
'~~~~~END_MODULE_CODE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
 
Erick37Commented:
Oops, you will also need to set the info for the height as well in the function pMyWindowProc:

mmi.ptMaxTrackSize.y = 18000 / Screen.TwipsPerPixelX
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
spraterAuthor Commented:
Thanks for the answer - it obviously took some time work up...but

Huh?????

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
0
 
spraterAuthor Commented:
I have found my answer to the form length/scroll bar issue at http://www.thescarms.com/VBasic/

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.

Thanks
Steve
0
 
Erick37Commented:
>>Your form size may not directly exceed the screen limits.<<

Yes it can, if you use the code in my previously rejected answer...
0
All Courses

From novice to tech pro — start learning today.