Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 214,051 times

Contents

Related Categories

Printing in VB - Pictures

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.

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Posted by bakuretsu on 27 Sep 2005

    Can you tell me how to set the margins and printer orientation also using this method. It should work in VB .NET 2003 I'm assuming.

    I need to be able to control the printer margins and headers and...

  • Cannot print from Local printer connected on Win X

    Posted by vasanthi on 27 Sep 2005

    [Hi,

    Facing problem in printing from local printer connected to WinXp from VB6. I am able to capture Printer.devicename and thru this print to network printer. But when trying to print on Local pri...

  • problem in printing

    Posted by aadreja on 04 Jul 2005

    hi suhaas

    have u added new paper...

    now go to properties of your generic printer..
    in printing preferences select default paper instead of letter select ur created custom paper...

    now open ...

  • Posted by suhaas on 04 Jul 2005

    hi aadreja,

    thanks for your reply.

    I tried to do as per your reply. But this does not work with VB6. I am working on a invoice printing application where I am using Generic Text printer with VB6...

  • custom paper size in xp

    Posted by aadreja on 04 Jul 2005

    for setting custom paper size in xp
    u have to create form...

    go to start->settings->printers
    in file menu go to "server properties"
    create new from with desired paper size... and give name

    n...