We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 212,916 times

Contents

Related Categories

Printing in VB - Line Statement

Line Statement

The first obvious drawing function is Line, which uses this syntax:

Printer.Line [Step] (x1, y1) [Step] - (x2, y2), [color], [B][F]

That might look at bit odd at the moment, so lets take a look. First of all, the (x1, y1) parameter tells VB the coordinates where you want the line to start. And so, the (x2, y2) parameter tells VB the coordinates where you want the line to end. The brackets surrounding the word 'Step' means that it is optional - you don't have to include it. If you include the first step (without the brackets), VB will draw the line relative to the CurrentX and CurrentY properties. This means, that if you passed Step (4,8) instead of the line starting 4 pixels (or whatever DrawMode you are in) from the left of the page, and 8 pixels from the top, it will draw the line 4 pixels to the right of CurrentX, and 8 pixels below CurrentY. Essentially,

Printer.Line Step (x1, y1)

is the same as

Printer.Line (x1 + Printer.CurrentX, y1 + Printer.CurrentY)

The final parameter specifies the colour of the line. The B and F options provide two more options. If B is specified, then VB will treat the second set of coordinates as the position of the bottom right hand corner of a box, and draw the box for you. If you use the B option, you can also give the F option, which means the box will be filled, using the graphic options described later.

Lets take a look at a few examples.

Printer.Line (1000, 2000)-(5000, 3000), vbRed
Printer.EndDoc

This code draws something like this:

Using the a combination of Line statements, and the Step keyword, we can also draw a box:

Printer.Line (1000, 2000)-(5000, 2000), vbRed
'Draw down from end of first line
'don't change X pos
'change Y pos by 4000
Printer.Line Step(0, 0)-Step(0, 2000), vbRed
'draw across 'change X pos by -4000
'don't change Y pos
Printer.Line Step(0, 0)-Step(-4000, 0), vbRed
'draw up
'don't change X pos
'change Y pos by -4000
Printer.Line Step(0, 0)-Step(0, -2000), vbRed
Printer.EndDoc

Of course, using the B statement, we can draw a box far more easily using the following code:

Printer.Line (1000, 2000)-(5000, 4000), vbRed, B
Printer.EndDoc

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...