VB icon

Create a form bigger than the screen!

Email
Submitted on: 1/1/2015 2:33:00 AM
By: VB Tips and Source Code (from psc cd)  
Level: Not Given
User Rating: By 5 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 5073
 
     The primary focus here is to allow you to display forms that are larger than the screen can show. Need an 8½" x 11" Form? NO Problem!The size used in this example is 8½" x 11", but it could just as easily be landscape, envelope, or any needed size.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Create a form bigger than the screen!
' Description:The primary focus here is to allow you to display forms that are larger than the screen can show. Need an 8½" x 11" Form? NO Problem!The size used in this example is 8½" x 11", but it could just as easily be landscape, envelope, or any needed size.
' By: VB Tips and Source Code (from psc cd)
'**************************************

Place a Horizontal Scrollbar on the form (doesn't matter where) and set its properties as follows: 
 Height =300
 LargeChange =900
 Name= HScroll
 SmallChange =30
These properties do not need to be identical to mine, but will serve as a good common ground starting point. You can always modify them to suit your needs and taste later. 
Now, let's place a Vertical Scrollbar on the form (doesn't matter where) and set its properties as follows: 
 LargeChange =900
 Name= VScroll
 SmallChange =30
 Width=300
Now, for the magic. Place a PictureBox on your form and set the following properties for it. The PictureBox will serve as our container for all controls and graphics that need to be placed on the virtual form. 
 BackColor=&H00FFFFFF&
 Height =15900
 Name= PicBox
 Width=11640
There is one last control that we need to place on the virtual form. However, this control is not placed directly onto the form but onto the picture box. It is a label that will serve as a filler to cover up the gap left between the two scrollbars in the lower right hand corner. Click on the PictureBox to select it, then double click the Label control on the VB Toolbox. Make sure that the label is the same color as your scrollbars. Then set its properties as follows: 
 Height =300
 Name= lblFiller
 Width=300
From this point on, all of the control that are placed on the virtual form (the picturebox) are solely for our own visual evidence that the form does indeed move. Place any controls you wish and set their properties as you wish on the form. (The downloadable project has already placed several controls on the picture box for you.) 
Let's start our Coding process by writing a routine to line everything up the way it should be. We need to place the scrollbars where they should go, make their dimensions match that of the form, and also position the lblFiller label properly. I have called this procedure AlignScrollBars(). This procedure needs to be placed in your General Decalrations section. The code looks like this: 
Sub AlignScrollBars()
' Resize the scrollbars
HScroll.Width = Me.ScaleWidth - lblFiller.Width
VScroll.Height = Me.ScaleHeight - lblFiller.Height
' Reposition the scrollbars
HScroll.Left = 0: HScroll.Top = Me.ScaleHeight - HScroll.Height
VScroll.Top = 0: VScroll.Left = Me.ScaleWidth - VScroll.Width
' Redimension the scrollbar parameters
HScroll.Max = PicBox.Width - Me.ScaleWidth
VScroll.Max = PicBox.Height - Me.ScaleHeight
' Reposition the PictureBox
PicBox.Top = (-1 * VScroll)
PicBox.Left = (-1 * HScroll)
' Reposition the Picturebox label by scrollbars
lblFiller.Top = VScroll.Height + VScroll - 30
lblFiller.Left = HScroll.Width + HScroll - 30
UpdateDisplay
End Sub
Note the call to UpdateDisplay. That procedure is just for the fun of it. I have used it to create some text and a graphic on the form at run time. This is what the procedure looks like. 
For VB4: 
Sub UpdateDisplay()
' Place text on the PictureBox
PicBox.AutoRedraw = True
Dim PictureBoxText As String
PictureBoxText = "Virtual Form - 8½ x 11 size"
With PicBox
.Font = "Arial"
.FontSize = 14
.FontBold = True
.FontItalic = True
.CurrentX = (PicBox.Width - PicBox.TextWidth(PictureBoxText)) / 2
.CurrentY = 0
End With
PicBox.Print PictureBoxText
' Graphics can be drawn on the virtual form at run time
PicBox.Line (100, 100)-(500, 500), , B
End Sub
For VB3: (since the WITH construct is only available in VB4.) 
Sub UpdateDisplay()
' Place text on the PictureBox
PicBox.AutoRedraw = True
Dim PictureBoxText As String
PictureBoxText = "Virtual Form - 8½ x 11 size"
PicBox.Font = "Arial"
PicBox.FontSize = 14
PicBox.FontBold = True
PicBox.FontItalic = True
PicBox.CurrentX = (PicBox.Width - PicBox.TextWidth(PictureBoxText)) / 2
PicBox.CurrentY = 0
PicBox.Print PictureBoxText
' Graphics can be drawn on the virtual form at run time
PicBox.Line (100, 100)-(500, 500), , B
End Sub
At this point, there are only three procedures left for us to code. We need to be able to realign the controls (scrollbars, etc) each time the scrollbars are clicked and each time the form is resized. I have written these three procedures like this: (Of course in VB3 you will want to remove the Private keyword from the SUB line). 
Private Sub Form_Resize()
AlignScrollBars
End Sub
Private Sub HScroll_Change()
AlignScrollBars
End Sub
Private Sub VScroll_Change()
AlignScrollBars
End Sub
Now, save your project and run the thing. If you have placed additional controls on the picturebox during design time, you should be able to see them float across the screen as your scroll around. Keep in mind that during design time, you can drag the picturebox around to work with the sections that are not visible within the form. The code will line everything back up so you don't even have to clean up behind yourself.


Other 4 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.