Printing in VB

Pictures

One other function is the PaintPicture method that allows you to output the contents of a graphics file to the printer object. The PaintPicture method uses this syntax:

Printer.PaintPicture picture, x1, y1, [width1], [height1], [x2], [y2], [width2], [height2], [opcode]

I won't cover everything here, so if you want more info, open up the MSDN library and select 'PaintPicture method' from the Index list. Picture is a IPictureDisp class, which can be retreived from a PictureBox or Forms Picture property, or using LoadPicture.

x1 and y1 specify the coordinates where the picture should be placed on the page. Width1 and Height1 set the width and height of the picture to be outputted, respectively. x2 and y2, in combination with width2 and height2 can be used to specify a clipping area from the source image.

Take a look at the examples below.

This code below outputs the picture contained within Picture1 to the printer, with 1000 twip (if this is the current scale mode) margins.

Printer.PaintPicture Picture1.Picture, 1000, 1000

This code,

PaintPicture LoadPicture("C:sample.jpg"), 1000, 1000

loads the file C:sample.jpg and outputs it onto a page.

Finally,

Printer.PaintPicture Picture1.Picture, 1000, 1000, 2000, 2000

resizes the picture in Picture1 to 2000x2000 pixels, and prints it.

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Anyone who considers arithmetic methods of producing random digits is, of course, in a state of sin.” - John von Neumann