Important alert: (current site time 7/16/2013 4:17:36 AM EDT)
 

VB icon

Create a form bigger than the screen!

Email
Submitted on: 6/9/1997
By: VB Tips and Source Code 
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: 53329
 
     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!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' 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
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=153&lngWId=1'for details.'**************************************

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 13 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

5/5/1999 3:45:00 PMJim Kelly

This is just what I need! I am very new to VB and am trying to print for the first time, so I decide to use PRINTFORM. The problem was I could only make a 7 x 5 form.
(If this comment was disrespectful, please report it.)

 
5/21/1999 7:26:00 AMDegziebob

This is almost what I'm looking for. I need the above program but I ALSO need to be able to create & design things on the area of screen. I have drawn lots of tables (like a football league ) that have arrays in them and I need to get them to be on the whole page. Anyone done this?
(If this comment was disrespectful, please report it.)

 
5/24/1999 7:39:00 PMMike Thompson

The code for making a form bigger than the screen is good, but how can you print the whole document complete?
(If this comment was disrespectful, please report it.)

 
6/8/1999 7:48:00 AMDennis Foley

I did everything, but when I use printform it doesn't work. I get a gray box on half the page and nothing more.

I created a button to call printform, is this not right???


(If this comment was disrespectful, please report it.)

 
6/9/1999 2:40:00 AMdegziebob

update: got all my info on the picbox...but I CANT print the form/picbox onto an A4 page, and as far as I know you can't....so the code is virtually useless. If anyone finds out how to do this then PLEASE EMAIL ME!!!
(If this comment was disrespectful, please report it.)

 
7/19/1999 8:54:00 AMSridharan

I tried to scroll a large Form. I succedded. But one thing. My project is to have a full chart on one form. Like Splitter window of VC++, I need to create Y-axis with 10 items and X-Axis with 24 hrs each and each vertical line indicates 2 mins. So I need to have more than 70,000 (in twips) width. How do I?. It is grateful to U sir...
(If this comment was disrespectful, please report it.)

 
7/21/1999 1:47:00 PMsmccarty

I am trying to design a Data Report in Landscape view, if anyone has done this please email your suggestions. Thanks.
(If this comment was disrespectful, please report it.)

 
10/1/1999 12:49:00 PMGerry Kompleski

Thanks. The example let me create a form that worked.
Upon creation of the form that is larger than the screen what is the code that will enable the end user to:
1.Use the page up/down keys to go through the page without having the focus on the scroll bar? (When the focus is on the scroll bar the keys work. But if the focus is on, let's say, a text box within the form those keys do not work.)
2.Go to the top/bottom when Ctrl home/end is pressed ?
3.Get the up/down arrow keys to scroll through multiple text boxes (as in excel)?
4.When tabbing down the form that is a row of text boxes I will tab to a text box lower than screen. How can I code the program to show the textbox on the screen that has been tabbed into?

I know this is a lot but any/all help would be appreciated. I am a novice that is just trying.

(If this comment was disrespectful, please report it.)

 
11/21/1999 10:23:00 AMBill

Looks good but like other people I need to print
whole 8.5X11 screen and have been unable to using printform
.If anyone has a cure for this please e mail me.
Thanks
(If this comment was disrespectful, please report it.)

 
12/28/1999 9:23:51 AMThe Journeyman

Okay, to all of those that cannot print the whole form:
Try painting the form onto a printer object.
(If this comment was disrespectful, please report it.)

 
5/27/2001 10:58:15 AMMox

Wow! Nice code, exactly what I was looking for too. Thanks!
(If this comment was disrespectful, please report it.)

 
4/7/2002 11:17:33 PMSharon Niles

Thank you, just what I was looking for.
(If this comment was disrespectful, please report it.)

 
4/26/2002 9:16:55 PMGeorge Renee

Looks good but like other people I need
to print
whole 8.5X11 screen and have
been unable to using printform
.If you has a remmedy for this please e
mail me.
Thanks

(If this comment was disrespectful, please report it.)

 
8/13/2002 6:39:50 PMGlen Starrett

Note: If you are using .Net and are searching for how to create a virtual area picturebox in VB.Net or C# (like I was...) then save yourself some time! The Panel class does exactly what you are probably looking for--just set AutoSize = True. If you still want the picturebox control in it, then drop a picturebox control on top of a panel. Or, of course, you can roll your own control in .Net by inheriting the System.Windows.Forms.ScrollableControl class.
(If this comment was disrespectful, please report it.)

 
9/26/2002 11:41:13 PM

The code is very good! I can see that the form can be a larger than I ever tried.
But I still don't know about the code how to painting the form
onto a printer object.
Please email me! Thanks.
(If this comment was disrespectful, please report it.)

 
12/24/2002 12:56:45 PMAnthony Dale Moore

Thank you this code helped alot.
Also those who are having trouble printing, you can also use the printer.pr method. a little bit of typing, but works
(If this comment was disrespectful, please report it.)

 
12/24/2002 12:57:49 PMAnthony Dale Moore

printer.print*
(If this comment was disrespectful, please report it.)

 
2/18/2003 11:14:51 PM

HOWTO: Print a Form That Is Too Large for the Screen or Page

http://support.microsoft.com/default.aspx?scid=kb;EN-US;230502

Got a problem, ask the expert...
(If this comment was disrespectful, please report it.)

 
2/18/2004 3:13:11 PM

I use a simular type of code for printing my large items... i also have buttons for switching pages... but anyway here is how i print everything that is on the form:
Private Sub mnuPrint_Click()
Printer.Print ""
Printer.PaintPicture
Me.PicBox.Picture, 0, 0
Printer.EndDoc
End Sub
(If this comment was disrespectful, please report it.)

 
2/18/2004 3:17:59 PM

Sorry... forgot to also mention that i sue this code in VB6 so not sure if it will work on any other versions or not
(If this comment was disrespectful, please report it.)

 
4/23/2004 4:36:09 AM

Hi,

Great! Just what I needed.
One more requirement here:
How can we print the contents of this picturebox to a printer into multiple pages?

Please do reply.

Regards

MANOJ
(If this comment was disrespectful, please report it.)

 
8/19/2004 3:15:55 PM

Hey Guys ,
I have the same problem as most of you. How do you print the form to A4, so that the whole of the A4 page is covered and not only 2/3 of the A4 page?

thanks

antonio_bantan@yahoo.co.uk
(If this comment was disrespectful, please report it.)

 
10/26/2005 7:16:30 AMjadk

I have the same problem as most of you. How do you print the form to A4, so that the whole of the A4 page is covered and not only 2/3 of the A4 page? thanks antonio jadk@walla.com
and also how can i resize the height of the form more than 11" like you do with the last example new virtual form 11 X 8.5 "


(If this comment was disrespectful, please report it.)

 
10/26/2005 7:25:00 AMjadk

hello'
please can you tell me where i must change into the code to get form for 10 pages for A4 ( more than 11")
(If this comment was disrespectful, please report it.)

 
10/26/2005 7:48:41 AMjadk

hi
i tried to print the form used printform '
but it print only what i see into the screen /
can u help me to send all the objects into the large form to the printer.
thanks jadkh@walla.com
(If this comment was disrespectful, please report it.)

 
10/26/2005 5:25:49 PMjadk

I have the same problem' I cant Print All The Opjects into the form that large than the screen .
if u can help me , thanks
jadkh@walla.com
(If this comment was disrespectful, please report it.)

 

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.