打印分页问题!!!!小弟急呀

cafu 2003-09-26 08:45:52
Public Class PrintingExample1
Inherits System.Windows.Forms.Form

....

private printFont As Font
private streamToPrint As StreamReader

Public Sub New ()
MyBase.New
InitializeComponent()
End Sub

'Event fired when the user presses the print button
Private Sub printButton_Click(sender As object, e As System.EventArgs)

Try
streamToPrint = new StreamReader ("PrintMe.Txt")
Try
printFont = new Font("Arial", 10)
Dim pd as PrintDocument = new PrintDocument() 'Assumes the default printer
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
pd.Print()
Finally
streamToPrint.Close()
End Try

Catch ex As Exception
MessageBox.Show("An error occurred printing the file - " + ex.Message)
End Try

End Sub

'Event fired for each page to print
Private Sub pd_PrintPage(sender As object, ev As System.Drawing.Printing.PrintPageEventArgs)

Dim lpp As Single = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
Dim line as String

'Work out the number of lines per page
'Use the MarginBounds on the event to do this
lpp = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

'Now iterate over the file printing out each line
'NOTE WELL: This assumes that a single line is not wider than the page width
'Check count first so that we don't read line that we won't print
line=streamToPrint.ReadLine()
while (count < lpp AND line <> Nothing)

yPos = topMargin + (count * printFont.GetHeight(ev.Graphics))

'Print Preview control will not work.
ev.Graphics.DrawString (line, printFont, Brushes.Black, leftMargin, _
yPos, new StringFormat())

count = count + 1

if (count < lpp) then
line=streamToPrint.ReadLine()
end if

End While

'If we have more lines then print another page
If (line <> Nothing) Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If

End Sub

....

End Class
那到点一下打印按扭就能打印全部页了,我想不会吧,这么解决要,请高手指点
...全文
60 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cafu 2003-09-26
  • 打赏
  • 举报
回复
在上面的代码里要添加什么代码呀?55555555555555
cafu 2003-09-26
  • 打赏
  • 举报
回复
这么选择呀,我是不要打印预缆功能,只要一个按纽,点了一下按纽就可以打印全部(不要去打印时选中 "Collate",在代码里先控制好
Anhowe 2003-09-26
  • 打赏
  • 举报
回复
打印时选中 "Collate" 就可以找印出全部的页了
cafu 2003-09-26
  • 打赏
  • 举报
回复
昨天发的这么没有了,是不是给别人删除了5555555555555]

16,556

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧