使用hasmorepages将行打印到下一页 [英] Printing line to next page using hasmorepages

查看:127
本文介绍了使用hasmorepages将行打印到下一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的按钮,一个按钮,一个PrintDocument1PrintPreviewDialog1
该按钮具有代码:
PrintPreviewDialog1.ShowDialog()

用于PrintDocument的代码是:

I have a simple from with one button, one PrintDocument1 and PrintPreviewDialog1
The button has code:
PrintPreviewDialog1.ShowDialog()

The code is for PrintDocument is:

Dim i As Byte
        While i < 200
            e.Graphics.DrawString(i.ToString, New Font("Times New Roman", 11), Brushes.Black, e.MarginBounds.X, e.MarginBounds.Y + i * 20)
            i = i + 1
        End While


但是打印页最多可以显示49行,而我需要200行.
我对放置e.hasmorepages的位置感到困惑.
请帮忙.


But the print page give maximum of 49 lines and I need 200 lines.
I am confused on where to put the e.hasmorepages.

Please help.

推荐答案

首先,您要在每一行上创建一个新的Font对象,但不要破坏它.这导致资源泄漏,您的应用最终将导致Windows崩溃.

在循环中需要它之前,先创建一次Font对象,然后在循环后对其进行处理.

e.HasMorePages在循环之后执行,但是您遇到了设计问题.您的代码将在每页上打印1到200.您似乎需要一个静态变量,该静态变量在开始打印时会初始化为1,并递增直到页面装满为止;如果还有更多行,请将e.HasMorePages设置为True.
First, you''r creating a new Font object on every line, but never destroying it. This leads to a resource leak and your app will eventually crash Windows.

Create the Font object once, before you need it in the loop, then Dispose it after the loop.

The e.HasMorePages goes after the loop, but you have a design problem. Your code will print 1 to 200 on every page. You seem to need a static that initializes to 1 when Print is started, increments until the page is full, and if there are more lines, set e.HasMorePages to True.


无字体不是问题

那是e.HasMorePages

每当我们设置e.HasMorePages = true时,一次又一次调用PrintDocument1.PrintPage

这是一个循环,因为我无法将其关闭

我找到了解决这个问题的方法
感谢老兄的帮助


供以后参考的人

只需使用这样的案例结构

将page_number调暗为字节
选择案例page_number
案例0
''''''''一些代码
e.HasMorePages = True
案例1
e.HasMorePages = false
''''''一些代码
案例2
e.HasMorePages = false
''''一些代码
结束选择
page_number = page_number + 1



还是谢谢你
No the font was not the problem

it was the e.HasMorePages

when ever we set e.HasMorePages = true the PrintDocument1.PrintPage is called again and again

it was a loop as i was not able to close it

I got the solution for this a
Thanks for the help dude


for people who refer it later

just use a case structure like this

Dim page_number as byte
Select Case page_number
Case 0
''''''''some code
e.HasMorePages = True
case 1
e.HasMorePages = false
'''''''' some code
case 2
e.HasMorePages = false
''''some code
end select
page_number = page_number + 1



Thanks anyway


这篇关于使用hasmorepages将行打印到下一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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