打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
vb.net 打印代碼

Imports System.Drawing.Printing

Imports System.IO

Public ClassForm1

   Dim inputStream As StreamReader

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) HandlesButton1.Click

       Dim pd As NewPrintDocument

       Try

           inputStream = NewStreamReader("D:\print.txt")

           AddHandler pd.PrintPage,AddressOf Me.pd_PrintPage

           pd.Print()

       Catch ex As Exception

           MsgBox("Error:"& ex.Message)

 

       Finally

           inputStream.Close()

       End Try

 

   End Sub

 

   Private Sub pd_PrintPage(ByVal sender As Object,ByVal ev As PrintPageEventArgs)

       Dim ypos As Integer =ev.MarginBounds.Top

       Dim count As Integer

       Dim currentLine As String

       Dim xpos As Integer =ev.MarginBounds.Left

       Dim f As NewFont("Times", 11)

       Dim lineHeight As Integer =f.GetHeight(ev.Graphics)

       Dim numOfLines As Integer =ev.MarginBounds.Height / lineHeight

 

       Do Until count = numOfLines

           currentLine = inputStream.ReadLine

           If currentLine Is NothingThen

               Exit Do

           End If

 

           ev.Graphics.DrawString(currentLine, f, Brushes.Black, xpos,ypos)

           ypos += lineHeight

           count += 1

 

 

           If Not currentLine Is NothingThen

               ev.HasMorePages = True

           Else

               ev.HasMorePages = False

 

           End If

 

       Loop

   End Sub

End Class

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
VB MSFlexGrid控件的几种简单的使用方法
VB打开EXCEL的方法
vb.net chart 动态曲线
第十一节 过程和函数
vba限制录入重复数
【例题】指针
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服