BUG: Must Call API to Print Color Text on Color Printer in VB

Last reviewed: June 21, 1995
Article ID: Q84269
The information in this article applies to:
  • Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0
  • Microsoft Visual Basic programming system for Windows, version 1.0

SYMPTOMS

Visual Basic for Windows does not directly support printing text in color to a color printer.

WORKAROUND

To print in color, you must first make a call to the Windows API function SetTextColor(). The example below shows how to implement this call into a Visual Basic application to allow for printing of colored text.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post more information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The ForeColor property of the Printer object was not fully implemented in Visual Basic. You can set the property, but the setting has no effect.

To send color output to a color printer, you must use the Windows API function call SetTextColor() instead of the ForeColor property of the Printer object.

Do the following to print "Hello" in all of the 16 QBColors:

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

  2. In the Form1 global module, add the following:

       ' Enter the following Declare statement on one, single line:
       Declare Function SetTextColor Lib "GDI" (ByVal hDC As Integer,
          ByVal crColor As Long) As Long
    
    

  3. In the Form1 Form_Click event procedure, add the following code:

       Sub Form_Click
          For i = 0 to 15
             x& = SetTextColor(Printer.HDC, QBColor(i))
             Printer.Print "Hello"
          Next i
          Printer.EndDoc
       End Sub
    
    

  4. Press F5 to run the program. Click the form.

The word "hello" will print in 16 different colors.


Additional reference words: buglist1.00 buglist2.00 buglist3.00 1.00 2.00
3.00
KBCategory: kbprint kbprg kbbuglist
KBSubcategory: APrgPrint


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.