FIX: Changing Default Printer Doesn't Effect Printer.Fonts

ID: Q99705


The information in this article applies to:


SYMPTOMS

If you change the default printer at run time, the Printer.Fonts enumeration is not updated. The Printer.Fonts enumeration is updated only after you print to the new default printer and use the EndDoc method.


WORKAROUND

To work around to this bug, choose one of these techniques:

  1. Use Printer.Print "" followed by Printer.EndDoc


  2. Call a DLL function which in turn calls the Windows API function EnumFontFamilies or EnumFonts. For a DLL code sample that shows how to enumerate fonts from a DLL, query on the following words in the Microsoft Knowledge Base:
    EnumFontFamilies AND EnumFonts


A disadvantage in using workaround 1 is that it will always cause a blank page to be ejected. A disadvantage of workaround 2 is that you will need to write a DLL using other Windows programming tools such as Microsoft Visual C++.


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem has been corrected in Visual Basic version 4.0.


MORE INFORMATION

To reproduce this bug, you will need to set up two printer devices for two types of printers. For example, you can set up LPT1 to use an Epson printer driver and LPT2 to use an HP LaserJet printer driver. The default printer will need to be set to one of these devices.

The steps below demonstrate using the Common Dialog custom control to change the default printer. This control is provided with the Microsoft Visual Basic Professional Toolkit version 1.0, the Microsoft Visual Basic Professional Edition version 2.0, and both the professional and standard editions of Microsoft Visual Basic version 3.0.

Steps to Reproduce Problem

  1. Start Visual Basic or from the File menu, choose New Project (ALT, F, N) if Visual Basic is already running.


  2. Add a common dialog (CMDialog1) control to Form1


  3. Add the following code to Form_Click for Form1
    
       Sub Form_Click ()
    
          Dim i As Integer
          CMDialog1.PrinterDefault = True
    
          'Show the Printer dialog
          CMDialog1.Action = 5
    
          Debug.Print Printer.FontCount
    
       End Sub
     


  4. From the Run menu, choose Start (ALT, R, S) or press F5 to run the program.


  5. Click Form1. The Printer Dialog is displayed.


  6. Choose the OK button to close the dialog. The number of fonts available will be displayed in the Debug Window.


  7. Click Form1 again. Select "Setup..." from the Printer dialog. The Printer Setup dialog is displayed.


  8. Set the default printer to a different printer and choose the OK button to close the Setup dialog.


  9. Choose the OK button on the Printer Dialog to close it.


The same number of fonts found in Step 6 will be displayed in the Debug Window. This demonstrates that Visual Basic did not update the Fonts list. If you step through the fonts in the Printer.Fonts enumeration, you will see the same set of fonts that were available in Step 6.

To see a different number of fonts displayed for the new default printer, from the Run menu, choose End (ALT, R, E) to end the program. Then press F5 to run it again, click Form1, and choose OK on the Printer Dialog.

Additional query words: buglist1.00 buglist2.00 buglist3.00 2.00 3.00 fixlist4.00


Keywords          : kbPrinting 
Version           : 1.00 2.00 3.00
Platform          : WINDOWS 
Issue type        : 

Last Reviewed: May 28, 1999