[请教]VB.net 打印的时候如何设置纸张大小

qqwanjun 2009-10-22 06:45:56
打印机默认纸张大小是A4的,
我用的是那种3连连续打印纸,希望按照我的要求连续进行打印,长度我可以计算出来,
请问如何设置纸张的长度.



'处理打印事件
Private WithEvents PrintText As New PrintDocument
'精确打印事件
Private Sub PrintText_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintText.PrintPage

Dim ps As New PageSettings
Dim myPaperSize As System.Drawing.Printing.PaperSize

myPaperSize = New System.Drawing.Printing.PaperSize("A4+", 210, 600)

ps.PaperSize = myPaperSize '设置为指定的纸张
ps.Landscape = False
PrintText.DefaultPageSettings = ps
PrintText.PrinterSettings.PrinterName = ps.PrinterSettings.PrinterName
End If

Dim Fmt As New StringFormat(StringFormatFlags.LineLimit)
Dim RectPrintingArea As New RectangleF
Dim Font As Font = New Font(New FontFamily("宋体"), 8, FontStyle.Bold)

Dim temp as string = "打印内容"
RectPrintingArea = New RectangleF(10, 10, 50, 20)
e.Graphics.DrawString(temp, Font1, Brushes.Black, RectPrintingArea, Fmt)


End Sub

...全文
456 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
_NET2004 2009-10-29
  • 打赏
  • 举报
回复
帮你顶上去
outou 2009-10-23
  • 打赏
  • 举报
回复
outou 2009-10-23
  • 打赏
  • 举报
回复
可以调用页面设置窗口进行设定呀,代码来自http://bingning.net/vb/source/graphics/pagesetupdialog.html

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'PrintDocument对象作成
Dim pd As New System.Drawing.Printing.PrintDocument
'PrintPage事件处理器追加
AddHandler pd.PrintPage, AddressOf pd_PrintPage

'PageSetupDialog类作成
Dim psd As New PageSetupDialog
'指定PrintDocument
psd.Document = pd
'表示页面设置窗体
If psd.ShowDialog() = DialogResult.OK Then
'OK被点击时打印
pd.Print()
End If
End Sub

Private Sub pd_PrintPage(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs)
'读取图片
Dim img As Image = Image.FromFile("test.bmp")
'描绘图片
e.Graphics.DrawImage(img, e.MarginBounds)
'没有下一页时通知
e.HasMorePages = False
'资源释放
img.Dispose()
End Sub

16,552

社区成员

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

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