如何使用PrintDocument设置边距 [英] How to set Margins using the PrintDocument

查看:1031
本文介绍了如何使用PrintDocument设置边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个打印报告,但我想允许用户设置边距。 我遇到的问题是我无法弄清楚它应该如何工作。 我有这个代码:

I have a report that prints but I would like to allow the user to set the margins.  The problem I'm having is I can not figure out how this is supposed to work.  I have this code:

   Private Sub rotHCReport_BeginPrint(ByVal sender As Object, _
          ByVal e As System.Drawing.Printing.PrintEventArgs) Handles Me.BeginPrint

        Me.OriginAtMargins = True
        Me.DefaultPageSettings.Margins = New Margins(20, 20, 23, 23)

    End Sub

  Private Sub rotHCReport_PrintPage(ByVal sender As Object, _
        ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles Me.PrintPage

     
        e.Graphics.PageUnit = GraphicsUnit.Inch
        'Print routine follows
 
  End Sub

我实际上通过PrintPage twicw来计算页数,以便我可以打印"第1页,共12页"。

I actually run through PrintPage twicw to count the pages so I can print "page 1 of 12"

这将产生以下输出:

如果我尝试通过在边距构造函数中发送25,25,25,25来将边距设置为1/4英寸,则不会打印任何内容。 没有打印的原因是因为边距被设置为某些超出范围的值。 如果我将代码更改为

If I try to set the margins to 1/4 of an inch by sending 25, 25, 25, 25 in the Margins constructor nothing prints.  The reason nothing prints is because the margins are being set to some out of range value.  If I change to code to

    Private Sub rotHCReport_BeginPrint(ByVal sender As Object, _
          ByVal e As System.Drawing.Printing.PrintEventArgs) Handles Me.BeginPrint

        Me.OriginAtMargins = True
        Me.DefaultPageSettings.Margins = New Margins(21, 20, 23, 23)

    End Sub

根据文件,这应该将左边距增加1/100英寸。 但这就是我得到的:

Which, according to the documentation, should increase the left margin by 1/100 th of an inch.  But this is what I get:

有人可以告诉我如何使用边距吗? 或者我是否需要对它们进行硬编码并告诉人们该软件允许的所有内容?

Can somebody tell me how I can use the margins?  Or do I have to hard code them and tell people thats all that the software allows?

谢谢

推荐答案

我尝试切换到毫米并获得了明智的结果。 我将使用英寸报告错误。
I tried switching to millimeters and received sensible results.  I will report a bug using inches.


这篇关于如何使用PrintDocument设置边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆