coding for printing

i would like to ask if there's anyone who can provide or suggest a code for printing in VB.

i have a program that has a menu -> file ->print

so wat should i write for the coding of my "mnuFilePrint" 's click event?
poeyserAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
FoyalConnect With a Mentor Commented:
Add a common dialog control to your project.

Private Sub mnuFilePrint_Click()

    On Error GoTo ErrHandler
   
    CommonDialog1.ShowPrinter
   
    PrintWhatever


ExitFilePrint:

    Exit Sub

ErrHandler:

    If Err = 32755 then Exit Sub

    msgbox "Error " & CStr(Err) & ": " & Err.Description
    Resume ExitFilePrint

End Sub

Private Sub PrintWhatever()

    On Error GoTo ErrHandler

    Printer.Print "whatever"
    Printer.EndDoc

ExitPrintWhatever:

    Exit Sub

ErrHandler:
 
    msgbox "Error " & CStr(Err) & ": " & Err.Description
    Resume ExitPrintWhatever

End Sub

0
 
FoyalCommented:
Use the Printer object to print to the default printer for the system... You can also change the default printer by selecting a printer from the Printers collection.

'set up what you want to print...

'print strings...
Printer.Print "Here is some text."

'or string variables...
S = "Here is some more text."
Printer.Print S

'use vb constants for alignment...
Printer.Print vbTab & "indented line."

'print formatted strings
Printer.Print Format(Now, "mmm dd,yyyy")

Printer.EndDoc 'print it

Look for this stuff in the help files.
There are alot of properties you can
access also with the common dialog control. (CommonDialog1.ShowPrinter)

0
 
csameer1Commented:
another important question is what you want to print?
0
 
FoyalCommented:
csameer1 is right. If you want to print some types of pictures you may need to go to the api. You can, however, print a picture which is contained in a picture box by using the printer.paintpicture method. Hope this helps.
0
 
csameer1Commented:
what do you want to print?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.