Results 1 to 6 of 6

Thread: Background color in Printer object.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    Kerala, India
    Posts
    275

    Background color in Printer object.

    Hi,

    Is there a way to print white letters on a black background using the Printer object?

  2. #2
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: Background color in Printer object.

    Think of the Printer page as a Form or PictureBox. It has most of the
    same methods/properties, except the Printer object doesn't have a BackColor.
    The code below prints the text on a form, but you can do the same
    with the Printer object.

    Code:
     Dim Txt As String
     Dim PosX As Single
     Dim PosY As Single
     Txt = "Hello From VB"
     PosX = 150
     PosY = 150
     Line (PosX, PosY)-(PosX + TextWidth(Txt), PosY + TextHeight(Txt)), vbBlack, BF  'Printer.Line
     CurrentX = PosX        'Printer.CurrentX
     CurrentY = PosY        'Printer.CurrentY
     ForeColor = vbWhite   'Printer.ForeColor
     Print Txt                  'Printer.Print
    Last edited by si_the_geek; Dec 11th, 2012 at 03:23 AM. Reason: fixed typo in code tags

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    Kerala, India
    Posts
    275

    Re: Background color in Printer object.

    Thank you VBClassicRocks

    Your code works. Thank you very much.
    Last edited by svg3414; Dec 9th, 2012 at 10:12 AM.

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Background color in Printer object.

    See if this does it.
    Code:
    Private Sub cmdPrint_Click()
        ' Use the line method to set the background color of the page
        Printer.Line (0, 0)-(Printer.Width, Printer.Height), vbBlack, BF
        ' Set the print color on the page
        Printer.ForeColor = vbWhite
        
        ' Set the print location
        Printer.CurrentX = 1440
        Printer.CurrentY = 1440
        
        ' Send some text to the printer
        Printer.Print "White text on black background"
        
        ' Release the document to the printer
        Printer.EndDoc
    End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    Kerala, India
    Posts
    275

    Re: Background color in Printer object.

    Quote Originally Posted by MarkT View Post
    See if this does it.
    Code:
    Private Sub cmdPrint_Click()
        ' Use the line method to set the background color of the page
        Printer.Line (0, 0)-(Printer.Width, Printer.Height), vbBlack, BF
        ' Set the print color on the page
        Printer.ForeColor = vbWhite
        
        ' Set the print location
        Printer.CurrentX = 1440
        Printer.CurrentY = 1440
        
        ' Send some text to the printer
        Printer.Print "White text on black background"
        
        ' Release the document to the printer
        Printer.EndDoc
    End Sub
    Actually the earlier code works. I had missed out a line while copying and pasting.

    Sorry for troubling you.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    Kerala, India
    Posts
    275

    Re: Background color in Printer object.

    Quote Originally Posted by MarkT View Post
    See if this does it.
    Code:
    Private Sub cmdPrint_Click()
        ' Use the line method to set the background color of the page
        Printer.Line (0, 0)-(Printer.Width, Printer.Height), vbBlack, BF
        ' Set the print color on the page
        Printer.ForeColor = vbWhite
        
        ' Set the print location
        Printer.CurrentX = 1440
        Printer.CurrentY = 1440
        
        ' Send some text to the printer
        Printer.Print "White text on black background"
        
        ' Release the document to the printer
        Printer.EndDoc
    End Sub
    Actually the earlier code works. I had missed out a line while copying and pasting.

    Sorry for troubling you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width