Printing a form In Visual Basic

Level:
Level1

As users begin to understand an application and use it to its full potential they often times need to print content for easier reading or permanent record. Fortunately Visual Basic 6 printing is not only easy but very advanced. One of the simplest ways to do printing is by using the PrintForm method which Visual Basic provides for us. This VB6 printing tutorial explains exactly what this method is and how you can use it in the applications you develop.

The PrintForm method sends an image of the current form to the default printer.

The sample application prints the image of the form shown below without the command buttons:

 

 

The code for this application is quite sparse (as it does not actually perform any calculations).

 

The Form_Load event contains code to center the form on the screen and to format the Date and Time labels:

 

Private Sub Form_Load()

 

'center the form:

Me.Top = (Screen.Height - Me.Height) / 2

Me.Left = (Screen.Width - Me.Width) / 2

 

'display date & time

lblDate.Caption = Format$(Date, "m/d/yyyy")

lblTime.Caption = Format$(Time, "h:nn AM/PM")

 

End Sub

 

The Click event for the Print button (cmdPrint_Click) hides the two command buttons (by setting their Visible properties to False), issues the PrintForm statement, then makes the buttons visible again:

 

Private Sub cmdPrint_Click()

 

cmdPrint.Visible = False

cmdExit.Visible = False

PrintForm

cmdPrint.Visible = True

cmdExit.Visible = True

End Sub

 

The Click event for the Exit button (cmdExit_Click) ends the program by issuing the End command.

 

Private Sub cmdExit_Click()

End

End Sub

 

Download the project files for this sample application here.

Written By TheVBProgramer.

If you enjoyed this post, subscribe for updates (it's free)

vb 6.0

1.i want to get data from database to my form
2.what is the use of msflexgrid
3.what is the use of datagrid
4.i want data to shown in text boxes or in any grid
i 'm using backend as access
5.i hve two combo box and commandbox as search,jst i want to search according to the combo box to show related things to be shown up in next form
ex : flight search :- source to destination search :- it will search some flight detail and i want to show that data in next form,
query is which will be easy to show in text boxex or in grid,if grid then help me with code

print form debug

there is debug in the line

PrintForm

huhuhu

its works,thnx :)

its works,thnx :)

how to print in landscape

when i use printfrom it print it as portrait and some items be missing i want to print it like landscape

I want to know that how can I

I want to know that how can I give a single command to take three printout of the Invoie on which different text is written.
i.e. Onriginal for Buyer in 1st Page,
Duplicate in 2nd Page.
Triplicate on 3rd Page.
These three of the copies in one control key.

Prinout problem

I want to know that how can I give a single command to take three printout of the Invoie on which different text is written.
i.e. Onriginal for Buyer in 1st Page,
Duplicate in 2nd Page.
Triplicate on 3rd Page.
These three of the copies in one control key.

Please guide

Thanku

Thanku sir this is realy helpfull for me...........%%

how to send codes to a printer

I will like to know the way to send codes to a printer for configuring it with quantity of lines for page (ie. half page) so when the instruction Printer.EndDoc comes the printer moves the paper only until line 32.

Thank you in advance.

Luis

sir can you help me with the codes!

sir can you help me with the codes I'm trying to print what is in the database using the print command button? by the way I'm using Microsoft access in my database

Nice

Nice post , how can i print form without printing background

try this

try this codes.

lblbackground.visible=false
printForm
lblbackground.visible=true. but make sure ur properties names are used and not as exactly as mine here

,,can you help me to print

,,can you help me to print the form in microsoftFlexGrid using visual basic 6.o...plzzzz......

What exactly are you trying

What exactly are you trying to print? The form or just the flexgrid.

You can use the PrintForm method and hide the controls that you don't want printed. You can also change all the colors of the Flexgrid so it will print nicely.

can you help me to print the

can you help me to print the form and its content send me the codes in robertjohn_delacruz1988@yahoo.com thanks so much to those who will help me asap....

how can i print data from a data grid...

i need to know about this... please help me... i'm new in visual basic 6.0... and i really need to know how to print these records, that will be appearing in my data grid...

Printing Data grid view

Was told i could get help from here! want the source codes of to be told how to print the data in my data grid form and should come out in that format, i dont want to print the form only the data

Printing from vb6 coding

how to print the data in my data grid form and should come out in that format, i dont want to print the form only the data

Printing from vb6 coding

how to print the data in my data grid form and should come out in that format, i dont want to print the form only the data

printing a different from within the project

I needed to write the code for printing a form in eg Form1 but the form I want to print is Form2. How do I do that?

Urgent help needed please!

Printing the Form Name when printing w/ "PrintForm"

I want to print the form name when I use printform. I can get my program to print the for, but it doesn't print the form name too.
Can you help?

printing vb form

in my application is i want print a vb form what is the code for printing a form

printing vb form

in my application is i want print a vb form what is the code for printing a form

code for printer for visual basic 6.0

what is the code of printer using visual basic 6.0
i create simple program using button and text box
how can print a letter in the printer using button

can u gave me some sulution for this matter

printer printing for ordering

' This will be how the print code for your ordering it will help
---------------------------------------------------------------------------------------------------------------------------
Private sub cmdPrint_Click
printer.print
printer.print
Printer Print Tab(2) Time + " "+ Date
Printer.print Tab(5) (label1.Caption "Cheese burger" + " " + (text1.txt "the amount or sum of money")
.
.
.
Printer.Print Tab(5) (Label1.Caption "Total" + " " (text17.text " the Total sum of money")
Printer.print
End sub
-----------------------------------------------------------------------------------------------------------------------
' you can used this code for printing
'for db and excell printing next time i log in I''ll post it tnx guys

the printer.print does not

the printer.print does not work with vb6!!!!!!!!

Skip the Page

How to skip the page during printing?

How to convert data stored in access db into excell using vb6.

I am designing Payment System using vb6 and i need to priview data stored in access database into the spreadsheet(excell), I have tried to to find codes to perfom such task but am not found of it. Thanxs in advance for those who will help me.
Chimwege W.

VB 6.0 Printing

In In my application currency figures in labels does not properly align (With different size of figures) as below when printing with specific location using PRINTER.PRINT command
456.00
34905.00
Therefore please be kind enough to make a solution for me
Regards
Damsiri
(damsirirm@hotmail.com)

thanks for the tips....

thanks for the tips

please help me for the print code for ordering system, i want print also the date and time same as the price.
can you give me some tips about the time code.
thanks a lot..

Plece help with print form in vb6

Can you send method printform from smateuszuk@op.pl

Regards
Stanisław Mateuszuk
Poland

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.