Printing text on top of grapics to the printer object


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Printing text on top of grapics to the printer object

  1. #1
    Sharon Thomas Guest

    Printing text on top of grapics to the printer object


    I am trying to print out a solid orange graphic. On top of the graphic I
    want to print some text. This text will include user input, which can change
    with each user. Using the PrintForm method works, using the form as a container
    for the picture and a label for the text. I set the AutoRedraw to True for
    the form and the picture. The only problem with this method, is that the
    visible area on the screen is the only thing that gets printed. The effects
    of using the PrintForm method is exactly what I am looking for, but with
    the capability of resizing the form and picture.

    If I print a graphic from a picture box and at the same time, print the text,
    through code or using a label, there is a white box around the text.


    If I print the picture and then put the paper back into the printer and print
    the text, it works; but I do not want to have to print twice.

    I have been working on this problem for months and am desperate at this point.
    This is a very important step for my employer, so if anyone can help, it
    will be very much appreciated.

    Thanks in advance,
    Sharon Thomas


  2. #2
    René Whitworth Guest

    Re: Printing text on top of grapics to the printer object

    You should try setting the background of the text to transparent using
    SetBkMode() API:
    Private Declare Function SetBkMode Lib "gdi32" (ByVal hDC As Long, ByVal
    nBkMode As Long) As Long
    Private Const TRANSPARENT = 1

    SetBkMode PrinterDC, TRANSPARENT

    --
    Hope this helps ...

    Rene Whitworth
    Whitworth Software Solutions - Germany
    http://www.w-s-s.de
    Please reply to the newsgroup :-)


    "Sharon Thomas" <Destani6@aol.com> schrieb im Newsbeitrag
    news:3904614d$1@news.devx.com...
    >
    > I am trying to print out a solid orange graphic. On top of the graphic I
    > want to print some text. This text will include user input, which can

    change
    > with each user. Using the PrintForm method works, using the form as a

    container
    > for the picture and a label for the text. I set the AutoRedraw to True for
    > the form and the picture. The only problem with this method, is that the
    > visible area on the screen is the only thing that gets printed. The

    effects
    > of using the PrintForm method is exactly what I am looking for, but with
    > the capability of resizing the form and picture.
    >
    > If I print a graphic from a picture box and at the same time, print the

    text,
    > through code or using a label, there is a white box around the text.
    >
    >
    > If I print the picture and then put the paper back into the printer and

    print
    > the text, it works; but I do not want to have to print twice.
    >
    > I have been working on this problem for months and am desperate at this

    point.
    > This is a very important step for my employer, so if anyone can help, it
    > will be very much appreciated.
    >
    > Thanks in advance,
    > Sharon Thomas
    >




  3. #3
    René Whitworth Guest

    Re: Printing text on top of grapics to the printer object

    You should try setting the background of the text to transparent using
    SetBkMode() API:
    Private Declare Function SetBkMode Lib "gdi32" (ByVal hDC As Long, ByVal
    nBkMode As Long) As Long
    Private Const TRANSPARENT = 1

    SetBkMode PrinterDC, TRANSPARENT

    --
    Hope this helps ...

    Rene Whitworth
    Whitworth Software Solutions - Germany
    http://www.w-s-s.de
    Please reply to the newsgroup :-)


    "Sharon Thomas" <Destani6@aol.com> schrieb im Newsbeitrag
    news:3904614d$1@news.devx.com...
    >
    > I am trying to print out a solid orange graphic. On top of the graphic I
    > want to print some text. This text will include user input, which can

    change
    > with each user. Using the PrintForm method works, using the form as a

    container
    > for the picture and a label for the text. I set the AutoRedraw to True for
    > the form and the picture. The only problem with this method, is that the
    > visible area on the screen is the only thing that gets printed. The

    effects
    > of using the PrintForm method is exactly what I am looking for, but with
    > the capability of resizing the form and picture.
    >
    > If I print a graphic from a picture box and at the same time, print the

    text,
    > through code or using a label, there is a white box around the text.
    >
    >
    > If I print the picture and then put the paper back into the printer and

    print
    > the text, it works; but I do not want to have to print twice.
    >
    > I have been working on this problem for months and am desperate at this

    point.
    > This is a very important step for my employer, so if anyone can help, it
    > will be very much appreciated.
    >
    > Thanks in advance,
    > Sharon Thomas
    >




  4. #4
    Phil Weber Guest

    Re: Printing text on top of grapics to the printer object

    Sharon: Rather than trying to copy what's on the screen to the printer, I
    would suggest using the methods of the Printer object to draw your text and
    graphics directly to the printer. You will be able to take advantage of the
    full resolution of your printer, and your output will be of much higher
    quality.

    For example, to print an orange box two inches wide by one inch high with a
    single-pixel black border and the text "Hello, World" centered in white
    text, you would do the following:

    Private Const TRANSPARENT As Long = 1
    Private Declare Function SetBkMode Lib "gdi32" _
    (ByVal hDC As Long, ByVal nBkMode As Long) As Long

    Dim sText As String
    Dim lHeight As Long
    Dim lWidth As Long

    ' 1440 twips per inch
    lHeight = 1440
    lWidth = 2880
    sText = "Hello, World"

    ' Initialize device context
    Printer.Print
    ' Draw orange box
    Printer.Line (0, 0)-(lWidth, lHeight), &H80FF&, BF
    ' Draw black border
    Printer.Line (0, 0)-(lWidth, lHeight), vbBlack, B

    With Printer
    ' Set font properties
    With .Font
    .Bold = True
    .Name = "Tahoma"
    .Size = 16
    End With
    .ForeColor = vbWhite
    .FontTransparent = True
    ' The following call is necessary to work around
    ' a bug in Windows 9x. See MSKB article Q145726
    ' for details.
    Call SetBkMode(.hDC, TRANSPARENT)
    ' Center text in box
    .CurrentX = (lWidth - .TextWidth(sText)) \ 2
    .CurrentY = (lHeight - .TextHeight(sText)) \ 2
    Printer.Print sText;
    .EndDoc
    End With

    ---
    Phil Weber



  5. #5
    Phil Weber Guest

    Re: Printing text on top of grapics to the printer object

    Sharon: Rather than trying to copy what's on the screen to the printer, I
    would suggest using the methods of the Printer object to draw your text and
    graphics directly to the printer. You will be able to take advantage of the
    full resolution of your printer, and your output will be of much higher
    quality.

    For example, to print an orange box two inches wide by one inch high with a
    single-pixel black border and the text "Hello, World" centered in white
    text, you would do the following:

    Private Const TRANSPARENT As Long = 1
    Private Declare Function SetBkMode Lib "gdi32" _
    (ByVal hDC As Long, ByVal nBkMode As Long) As Long

    Dim sText As String
    Dim lHeight As Long
    Dim lWidth As Long

    ' 1440 twips per inch
    lHeight = 1440
    lWidth = 2880
    sText = "Hello, World"

    ' Initialize device context
    Printer.Print
    ' Draw orange box
    Printer.Line (0, 0)-(lWidth, lHeight), &H80FF&, BF
    ' Draw black border
    Printer.Line (0, 0)-(lWidth, lHeight), vbBlack, B

    With Printer
    ' Set font properties
    With .Font
    .Bold = True
    .Name = "Tahoma"
    .Size = 16
    End With
    .ForeColor = vbWhite
    .FontTransparent = True
    ' The following call is necessary to work around
    ' a bug in Windows 9x. See MSKB article Q145726
    ' for details.
    Call SetBkMode(.hDC, TRANSPARENT)
    ' Center text in box
    .CurrentX = (lWidth - .TextWidth(sText)) \ 2
    .CurrentY = (lHeight - .TextHeight(sText)) \ 2
    Printer.Print sText;
    .EndDoc
    End With

    ---
    Phil Weber



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center