PRINT picturebox from richtextbox

User avatar
sal21
PlatinumLounger
Posts: 4346
Joined: 26 Apr 2010, 17:36

PRINT picturebox from richtextbox

Post by sal21 »

i know the way to print a string with printer.print object.

but how to print also the picture box in richtextbox?

.. or have the printer object a statement to print the image?

note:
i copy of picturebox is hided in form.
the image of picturebox is stored in c:\mydir\lido.bmp
to print the string line from richtextbox i have maked a loop line by line
naturally the picturebox is the image of beach in the recepit/invoice:--)
You do not have the required permissions to view the files attached to this post.

User avatar
sal21
PlatinumLounger
Posts: 4346
Joined: 26 Apr 2010, 17:36

Re: PRINT picturebox from richtextbox

Post by sal21 »

progress

Printer.PaintPicture Picture1, 0, 0
Printer.Print vbCrLf & vbCrLf & vbCrLf & vbCrLf

now how to center the image whe print?

User avatar
SpeakEasy
4StarLounger
Posts: 544
Joined: 27 Jun 2021, 10:46

Re: PRINT picturebox from richtextbox

Post by SpeakEasy »

Printer has Width and Height. As does the picture you are painting - so you can position it, e.g.

Printer.PaintPicture Picture1, x, y

by calculating x and y in a similar way to the method provided to you to centre text the other day https://eileenslounge.com/viewtopic.php?f=30&t=37298. There are a couiple of little caveats, the main one being that we actually need to work in the ScaleMode of the Printer object, but that's easily done. SO something like the following:

Code: Select all

    Dim x As Double
    Dim y As Double
    Dim wid As Double
    Dim hgt As Double
          
    ' We need to be working in ScaleMode units of the Printer object
    wid = ScaleX(Picture2.ScaleWidth, Picture2.ScaleMode, Printer.ScaleMode)
    hgt = ScaleY(Picture2.ScaleHeight, Picture2.ScaleMode, Printer.ScaleMode)

    x = Printer.ScaleLeft + (Printer.ScaleWidth - wid) / 2
    y = Printer.ScaleTop + (Printer.ScaleHeight - hgt) / 2

    Printer.PaintPicture Picture2, x, y

    Printer.EndDoc