Home All Groups Group Topic Archive Search About

Override Printer Margins (?)

Author
3 Jul 2006 8:35 PM
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

Author
4 Jul 2006 9:16 AM
Walter Wang [MSFT]
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 (waw***@online.microsoft.com, 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.
Author
4 Jul 2006 12:02 PM
Anne DeBlois
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

"Walter Wang [MSFT]" <waw***@online.microsoft.com> a écrit dans le message
de news: EZoOJq0nGHA.5***@TK2MSFTNGXA01.phx.gbl...
Show quoteHide quote
> 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 (waw***@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
Author
5 Jul 2006 5:24 AM
Walter Wang [MSFT]
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 (waw***@online.microsoft.com, 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.
Author
20 Sep 2006 3:34 PM
Anne DeBlois
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
Author
20 Sep 2006 7:12 PM
Anne DeBlois
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

"Anne DeBlois" <annedeblois@community.nospam> a écrit dans le message de
news: e2ob2oM3GHA.1***@TK2MSFTNGP06.phx.gbl...
Show quoteHide quote
> 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
>
Author
22 Sep 2006 3:55 AM
Walter Wang [MSFT]
Hi Anne,

I've created a simple WinForm application for you to test. The WinForm has
three buttons: use the button "Page Setup" to change the margins and
printer. Use the button "Print Preview" to view current document's preview
and print.

Note: you will have to use Outlook Express to download the attachment; or
you can send email to me first and I will send the project to you via email.

Please test it and tell me the result. I've tested it on one laser printer,
and the virtual printer "Microsoft Office Document Image Writer", both
works correctly.

Sincerely,
Walter Wang (waw***@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

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