Override Printer Margins (?)

  • Thread starter Thread starter Anne DeBlois
  • Start date Start date
A

Anne DeBlois

Hi,

We are developing a database application in Visual Basic.NET 2005. The
application will print label pages. Using the PrintDocument and GDI+
classes, I noticed a slight change when printing to a laser printer and when
printing to an inkjet printer. It's got to be the margins (defined by the
printer driver).

Is it possible to programmatically override the driver's margins in VB (at
our risks)? If so, how to? Thanks in advance,

ANNE DEBLOIS
 
Hi Anne,

Thank you for your post.

Based on my understanding, your question is how to control printed page's
margin. If I've misunderstood anything, please feel free to post here.

You can force the printer use your specified margins by setting
PrintDocument.DefaultPageSettings.Margins, for example:

PrintDocument1.DefaultPageSettings.Margins = New Printing.Margins(0, 0,
0, 0)
PrintDocument1.OriginAtMargins = True
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()

When OriginAtMargins is true, the Graphics object location takes into
account the PageSettings.Margins property value and the printable area of
the page. When OriginAtMargins is false, only the printable area of the
page is used to determine the location of the Graphics object origin, the
PageSettings.Margins value is ignored.

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi,

I think you got it right, at least for now, I think this is what I was
looking for.

Thank you, Mr. Wang!

Anne
 
Hi,

Appreciate your update and response. If you have any other questions or
concerns, please do not hesitate to contact us. It is always our pleasure
to be of assistance.

Have a nice day!

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi,

I am sorry for the delay. I just tried the code you provided:
PrintDocument1.DefaultPageSettings.Margins = New Printing.Margins(0, 0,
0, 0)
PrintDocument1.OriginAtMargins = True

I added this code to print a rectangle located at the very upperleft corner
of the page:

Dim rectangle As New Rectangle(0, 0, 400, 80)

e.Graphics.FillRectangle(Brushes.Cyan, rectangle)

e.Graphics.DrawRectangle(Pens.Cyan, rectangle)


I tried it two different printers, and I got my rectangle printed within a
1-inch margin!! Something has got to be wrong in my code...

Anne
 
Hi,

I also changed the following line:
PrintDocument1.DefaultPageSettings.Margins = New Printing.Margins(0, 0, 0,
0)

To this code:
PrinterDocument1.PrinterSettings.DefaultPageSettings.Margins = New
Printing.Margins(0,0,0,0)

Still no luck

I even changed the zeros for 200, and expected a 2-inch margin, but again I
got 1 inch.

What might be the problem? I am using .NET 2.0 (VS 2005)

ANNE DEBLOIS
 
Back
Top