Printer Control in VB6

I have a VB6 program that uses straight printer. type commands to the default printer.
I now need to print a logo and the Dim text fields.  
How do i add a printer control so that the user can select the printer they want?
Should my logo/data shoot to the printer directly or go to a Form first? (I am not using a database)  Please show instruction, Thank You
GarySBAsked:
Who is Participating?
 
VBClassicGuyCommented:
Here's how I do it (excuse my use of Implicit variable declaration):

   Rem *** Save default printer ***
   For i% = 0 To Printers.Count - 1
      If Printers(i%).DeviceName = Printer.DeviceName Then
         SavedPrn% = i%   'this variable is a public (global) variable
         Exit For
      End If
   Next i%

' Select your printer here. I have a dialog for this, or use the common dialog.

' Do your printing...

   Rem *** Restore default printer ***
   Set Printer = Printers(SavedPrn%)

HERE IS HOW I PRINT A LOGO IN THE "HEADER" OF MY REPORTS:

(note that "Alpha" is the name of my opening "start" form that has the logo on it)
(this code allows me to call this routine from any other form)
(my logo is contained in the pctPrint PictureBox control)

   Alpha.pctPrint.ScaleMode = vbPixels
   start% = (Printer.ScaleWidth / 2) - (Alpha.pctPrint.Width / 2)
   Call Printer.PaintPicture(Alpha.pctPrint.Picture, start%, Printer.CurrentY)
   Printer.CurrentY = Printer.CurrentY + Alpha.pctPrint.Height
0
 
Martin LissOlder than dirtCommented:
Dim WhatYouWantToPrint As String
 

CommonDialog1.ShowPrinter
Printer.Print WhatYouWantToPrint, CommonDialog1.hDC

Open in new window

0
 
pancholeftyCommented:
This isn't a runnable answer to your question. It's a couple of building blocks that you may find useful if you want more control of your UI and/or your app needs to have the ability to send different jobs, such as reports vs.receipts, to different printers.  

In your Preferences dialog, the user picks the printer for the job from a combo (dropdown list). You can store the selection in a config file or similar for later.

 
Dim i       As Integer

With cboPrinters
    
    For i = 0 To Printers.Count - 1
        
        .AddItem Printers(i).DeviceName
            
    Next
        
End With

Open in new window


Then assign the selection to a global variable:

 
g_strPrinterName = cboPrinters.Text ' or read it from the config file

Open in new window


When you get ready to print:

 
Dim prn	As Printer

For Each prn In Printers

    If (prn.DeviceName = g_strPrinterName) Then

        Set Printer = prn
        Exit For

    End If

Next

Open in new window

0
 
GarySBAuthor Commented:
Both answers were exactly what I needed, Thanks
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.