怎样用代码控制打印机进行横向换页 ??

hzybc 2006-02-18 11:17:53
因打印的栏目较多,需要用多张纸来打印表的头部

用 e.HasMorePages = True 可以实现纵向的换页,

用什么代码能实现横向换页???
...全文
148 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
夜雨悠扬 2006-02-21
  • 打赏
  • 举报
回复
如果必须这么做的话,只能用代码往打印机上写,现在提供的各种控件都没有这个功能,
以前用C++的时候就碰到了这个问题,如果你的报表比较规矩的话,应该很快就能够实现了。
长江支流 2006-02-21
  • 打赏
  • 举报
回复
楼主可以用二级缓存,用一个完全能容纳打印宽度的bmp,
然后设置Graphics的剪切区,把bmp画上去,
当剪切区宽度<bmp.Width时
e.HasMorePages = True
换页
此时,再把bmp后面的没打印的区域画到Graphics上...

画图方法Graphics.DrawImage(bmp)


lidong6 2006-02-21
  • 打赏
  • 举报
回复
e.HasMorePages = True 可以实现纵向的换页

=====================================
各位搞错了吧,楼主说的是横向换页,不是横向打印.



Snrmnm_sx 2006-02-21
  • 打赏
  • 举报
回复
H_R = 1
Dim drawRect1 As New RectangleF(Left_0, Height_1, 30, H_R * Height_A)
e.Graphics.DrawRectangle(blackPen, Left_0, Height_1, 30, H_R * Height_A)
e.Graphics.DrawString(" ", PrintFont, Brushes.Black, drawRect1, New StringFormat())
'故障时间
Str_P = " "
Dim drawRect2 As New RectangleF(Left_1, Height_1, 40, H_R * Height_A)
e.Graphics.DrawRectangle(blackPen, Left_1, Height_1, 40, H_R * Height_A)
e.Graphics.DrawString(Str_P, PrintFont, Brushes.Black, drawRect2, New StringFormat())
'故障地点
Str_P = " "
Dim drawRect3 As New RectangleF(Left_2, Height_1, 60, H_R * Height_A)
e.Graphics.DrawRectangle(blackPen, Left_2, Height_1, 60, H_R * Height_A)
e.Graphics.DrawString(Str_P, PrintFont, Brushes.Black, drawRect3, New StringFormat())
'发生时分
Str_P = " "
Dim drawRect4 As New RectangleF(Left_3, Height_1, 50, H_R * Height_A)
e.Graphics.DrawRectangle(blackPen, Left_3, Height_1, 50, H_R * Height_A)
e.Graphics.DrawString(Str_P, PrintFont, Brushes.Black, drawRect4, New StringFormat())
'修复时分
Str_P = " "
Dim drawRect5 As New RectangleF(Left_4, Height_1, 50, H_R * Height_A)
e.Graphics.DrawRectangle(blackPen, Left_4, Height_1, 50, H_R * Height_A)
e.Graphics.DrawString(Str_P, PrintFont, Brushes.Black, drawRect5, New StringFormat())
'故障延时
Str_P = " "
Dim drawRect6 As New RectangleF(Left_5, Height_1, 50, H_R * Height_A)
e.Graphics.DrawRectangle(blackPen, Left_5, Height_1, 50, H_R * Height_A)
e.Graphics.DrawString(Str_P, PrintFont, Brushes.Black, drawRect6, New StringFormat())
'影响列车客/总
Str_P = " "
Dim drawRect7 As New RectangleF(Left_6, Height_1, 50, H_R * Height_A)
e.Graphics.DrawRectangle(blackPen, Left_6, Height_1, 50, H_R * Height_A)
e.Graphics.DrawString(Str_P, PrintFont, Brushes.Black, drawRect7, New StringFormat())
'延误列车时分
Str_P = " "
Dim drawRect8 As New RectangleF(Left_7, Height_1, 50, H_R * Height_A)
e.Graphics.DrawRectangle(blackPen, Left_7, Height_1, 50, H_R * Height_A)
e.Graphics.DrawString(Str_P, PrintFont, Brushes.Black, drawRect8, New StringFormat())
'原因
Str_P = " "
Dim drawRect9 As New RectangleF(Left_8, Height_1, 475, H_R * Height_A)
e.Graphics.DrawRectangle(blackPen, Left_8, Height_1, 475, H_R * Height_A)
e.Graphics.DrawString(Str_P, PrintFont, Brushes.Black, drawRect9, New StringFormat())
'故障归属
Str_P = " "
Dim drawRect10 As New RectangleF(Left_9, Height_1, 40, H_R * Height_A)
e.Graphics.DrawRectangle(blackPen, Left_9, Height_1, 40, H_R * Height_A)
e.Graphics.DrawString(Str_P, PrintFont, Brushes.Black, drawRect10, New StringFormat())
'故障设备
Str_P = " "
Dim drawRect11 As New RectangleF(Left_10, Height_1, 55, H_R * Height_A)
e.Graphics.DrawRectangle(blackPen, Left_10, Height_1, 55, H_R * Height_A)
e.Graphics.DrawString(Str_P, PrintFont, Brushes.Black, drawRect11, New StringFormat())
'故障原因
Str_P = " "
Dim drawRect12 As New RectangleF(Left_11, Height_1, 40, H_R * Height_A)
e.Graphics.DrawRectangle(blackPen, Left_11, Height_1, 40, H_R * Height_A)
e.Graphics.DrawString(Str_P, PrintFont, Brushes.Black, drawRect12, New StringFormat())

'故障器材
Str_P = " "
Dim drawRect13 As New RectangleF(Left_12, Height_1, 55, H_R * Height_A)
e.Graphics.DrawRectangle(blackPen, Left_12, Height_1, 55, H_R * Height_A)
e.Graphics.DrawString(Str_P, PrintFont, Brushes.Black, drawRect13, New StringFormat())
Str_P = " "
Dim drawRect15 As New RectangleF(Left_13, Height_1, 64, H_R * Height_A)
e.Graphics.DrawRectangle(blackPen, Left_13, Height_1, 64, H_R * Height_A)
e.Graphics.DrawString(Str_P, PrintFont, Brushes.Black, drawRect15, New StringFormat())
Height_1 = Height_1 + Height_A
Top_D = Height_1
End If
If Row_N <> 0 And aa < Row_N Then
If aa = 0 And aaa1 = 0 Then
aa1 = aa1 + 1
e.Graphics.DrawLine(Pen0, Left_0, Top_A, Right_0, Top_A)
e.Graphics.DrawLine(Pen0, Left_0, Top_A + Height_A, Right_0, Top_A + +Height_A)
e.Graphics.DrawLine(Pen0, Left_0, Top_A + 3 * Height_A, Right_0, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Left_0, Top_A, Left_0, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Right_0, Top_A, Right_0, Top_A + +3 * Height_A)
Bt = "一、安全信息:" + "备注栏中填写的‘安’表示安监室有记录;‘调’表示调度所有记录;‘漏’表示漏报;‘运8’表示运报8有记录)"
e.Graphics.DrawString(Bt, PrintFont_A, Brushes.Black, Left_0 + 2, Top_A + 2, New StringFormat())
If aa <> 0 Then
e.Graphics.DrawLine(Pen0, Left_0, Top_A, Right_0, Top_A)
e.Graphics.DrawLine(Pen0, Left_0, Top_A + Height_A, Right_0, Top_A + +Height_A)
e.Graphics.DrawLine(Pen0, Left_0, Top_A + 3 * Height_A, Right_0, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Left_0, Top_A, Left_0, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Right_0, Top_A, Right_0, Top_A + +3 * Height_A)
End If
还有没有发完呢!
Snrmnm_sx 2006-02-21
  • 打赏
  • 举报
回复
e.Graphics.DrawLine(Pen0, Left_1, Top_A + Height_A, Left_1, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Left_2, Top_A + Height_A, Left_2, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Left_3, Top_A + Height_A, Left_3, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Left_4, Top_A + Height_A, Left_4, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Left_5, Top_A + Height_A, Left_5, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Left_6, Top_A + Height_A, Left_6, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Left_7, Top_A + Height_A, Left_7, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Left_8, Top_A + Height_A, Left_8, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Left_9, Top_A + Height_A, Left_9, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Left_10, Top_A + Height_A, Left_10, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Left_11, Top_A + Height_A, Left_11, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Left_12, Top_A + Height_A, Left_12, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Left_13, Top_A + Height_A, Left_13, Top_A + +3 * Height_A)
'e.Graphics.DrawLine(Pen0, Left_14, Top_A + Height_A, Left_14, Top_A + +3 * Height_A)
e.Graphics.DrawString("序", PrintFont, Brushes.Black, Left_0 + 2, Top_A + Height_A + 2, New StringFormat())
e.Graphics.DrawString("故障", PrintFont, Brushes.Black, Left_1 + 2, Top_A + Height_A + 2, New StringFormat())
e.Graphics.DrawString(" 故障", PrintFont, Brushes.Black, Left_2 + 2, Top_A + Height_A + 2, New StringFormat())
e.Graphics.DrawString(" 发生", PrintFont, Brushes.Black, Left_3 + 2, Top_A + Height_A + 2, New StringFormat())
e.Graphics.DrawString(" 修复", PrintFont, Brushes.Black, Left_4 + 2, Top_A + Height_A + 2, New StringFormat())
e.Graphics.DrawString(" 故障", PrintFont, Brushes.Black, Left_5 + 2, Top_A + Height_A + 2, New StringFormat())
e.Graphics.DrawString("影响", PrintFont_C, Brushes.Black, Left_6 + 2, Top_A + Height_A + 2, New StringFormat())
e.Graphics.DrawString("延误列", PrintFont_C, Brushes.Black, Left_7 + 2, Top_A + Height_A + 2, New StringFormat())
e.Graphics.DrawString(" 故障现象 原因分析", PrintFont, Brushes.Black, Left_8 + 2, Top_A + Height_A + 2, New StringFormat())
e.Graphics.DrawString("故障", PrintFont, Brushes.Black, Left_9 + 2, Top_A + Height_A + 2, New StringFormat())
e.Graphics.DrawString(" 故障", PrintFont, Brushes.Black, Left_10 + 2, Top_A + Height_A + 2, New StringFormat())
e.Graphics.DrawString("故障", PrintFont, Brushes.Black, Left_11 + 2, Top_A + Height_A + 2, New StringFormat())
e.Graphics.DrawString(" 原因", PrintFont, Brushes.Black, Left_12 + 2, Top_A + Height_A + 2, New StringFormat())
e.Graphics.DrawString(" 备", PrintFont, Brushes.Black, Left_13 + 4, Top_A + Height_A + 2, New StringFormat())
e.Graphics.DrawString("号", PrintFont, Brushes.Black, Left_0 + 2, Top_A + 2 * Height_A + 2, New StringFormat())
e.Graphics.DrawString("日期", PrintFont, Brushes.Black, Left_1 + 2, Top_A + 2 * Height_A + 2, New StringFormat())
e.Graphics.DrawString(" 地点", PrintFont, Brushes.Black, Left_2 + 2, Top_A + 2 * Height_A + 2, New StringFormat())
e.Graphics.DrawString(" 时分", PrintFont, Brushes.Black, Left_3 + 2, Top_A + 2 * Height_A + 2, New StringFormat())
e.Graphics.DrawString(" 时分", PrintFont, Brushes.Black, Left_4 + 2, Top_A + 2 * Height_A + 2, New StringFormat())
e.Graphics.DrawString(" 延时", PrintFont, Brushes.Black, Left_5 + 2, Top_A + 2 * Height_A + 2, New StringFormat())
e.Graphics.DrawString("客/总", PrintFont_C, Brushes.Black, Left_6 + 2, Top_A + 2 * Height_A + 2, New StringFormat())
e.Graphics.DrawString("车时分", PrintFont_C, Brushes.Black, Left_7 + 2, Top_A + 2 * Height_A + 2, New StringFormat())
e.Graphics.DrawString(" 影响情况 处理经过", PrintFont, Brushes.Black, Left_8 + 2, Top_A + 2 * Height_A + 2, New StringFormat())
e.Graphics.DrawString("归属", PrintFont, Brushes.Black, Left_9 + 2, Top_A + 2 * Height_A + 2, New StringFormat())
e.Graphics.DrawString(" 设备", PrintFont, Brushes.Black, Left_10 + 2, Top_A + 2 * Height_A + 2, New StringFormat())
e.Graphics.DrawString("原因", PrintFont, Brushes.Black, Left_11 + 2, Top_A + 2 * Height_A + 2, New StringFormat())
e.Graphics.DrawString(" 归属", PrintFont, Brushes.Black, Left_12 + 2, Top_A + 2 * Height_A + 2, New StringFormat())
e.Graphics.DrawString(" 注", PrintFont, Brushes.Black, Left_13 + 4, Top_A + 2 * Height_A + 2, New StringFormat())
Height_1 = Top_A + 3 * Height_A
Snrmnm_sx 2006-02-21
  • 打赏
  • 举报
回复
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Try
Dim PrintFont, HeaderFont, PrintFont_A, PrintFont_B, PrintFont_C As Font
Dim Height_H, Width_H As Single '每行高度,宽度
Dim Slr_Num As Integer
Dim Bt As String
Dim HeaderLeft, HeaderTop As Single
Dim Leftp, Topp As Single
Dim Dw0, Zbdd0, Rq0 As String
Dim i, j, k As Integer
Dim Pen0 As New Pen(Color.Black, 1)
Dim Row_N, Row_N1, Row_N2, H_R, H_R1 As Integer
Row_N = workTable.Rows.Count
Row_N1 = Tb2.Rows.Count
Row_N2 = Tb3.Rows.Count
PrintFont = New Font("仿宋_GB2312", 11, FontStyle.Regular)
PrintFont_A = New Font("仿宋_GB2312", 11, FontStyle.Bold)
PrintFont_B = New Font("仿宋_GB2312", 13, FontStyle.Regular)
PrintFont_C = New Font("仿宋_GB2312", 11, FontStyle.Regular)
HeaderFont = New Font("仿宋_GB2312", 22, FontStyle.Bold)
'布面设置
Dim Left_0, Right_0, Left_1, Left_2, Left_3, Left_4, Left_5, Left_6, Left_7, Left_8, Left_9, Left_10, Left_11, Left_12, Left_13, Left_14 As Integer
Dim Top_A, Height_A As Integer
Left_0 = 15
Right_0 = e.PageBounds.Width - 45
Height_A = PrintFont.GetHeight(e.Graphics) + 3
Dim Bottom_1, x, y As Single
Dim Str_P As String
Dim blackPen As New Pen(Color.Black)
'表头
If aa1 > 1 Then
Top_A = 40
Else
HeaderLeft = 360
HeaderTop = 40
Height_H = PrintFont.GetHeight(e.Graphics) + 6
Width_H = e.PageBounds.Width - 2 * e.MarginBounds.Left
Bt = TBDW.Text + "电务调度报表"
e.Graphics.DrawString(Bt, HeaderFont, Brushes.Black, HeaderLeft, HeaderTop, New StringFormat())
Dw0 = "单位: " + TBDW.Text
Rq0 = "日期范围:" + "(" + FormatDateTime(TJRQ1.Value, DateFormat.LongDate) + "-" + FormatDateTime(TJRQ2.Value, DateFormat.LongDate) + ")" + " 制表日期:" + FormatDateTime(Format(Date.Now, "yyyy年MM月dd日"), DateFormat.LongDate)
Leftp = 100
Topp = HeaderTop + 2 * PrintFont.GetHeight(e.Graphics) + 10
e.Graphics.DrawString(Dw0, PrintFont_B, Brushes.Black, Left_0, Topp, New StringFormat())
e.Graphics.DrawString(Rq0, PrintFont_B, Brushes.Black, Leftp + 260, Topp, New StringFormat())
Top_A = Topp + Height_A
End If
'画安全信息表头-------------------------------------------------------------------------------
If Row_N = 0 And aa1 = 0 Then
aa1 = aa1 + 1
e.Graphics.DrawLine(Pen0, Left_0, Top_A, Right_0, Top_A)
e.Graphics.DrawLine(Pen0, Left_0, Top_A + Height_A, Right_0, Top_A + +Height_A)
e.Graphics.DrawLine(Pen0, Left_0, Top_A + 3 * Height_A, Right_0, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Left_0, Top_A, Left_0, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Right_0, Top_A, Right_0, Top_A + +3 * Height_A)
Bt = "一、安全信息:" + "备注栏中填写的‘安’表示安监室有记录;‘调’表示调度所有记录;‘漏’表示漏报;‘运8’表示运报8有记录)"
e.Graphics.DrawString(Bt, PrintFont_A, Brushes.Black, Left_0 + 2, Top_A + 2, New StringFormat())
If aa <> 0 Then
e.Graphics.DrawLine(Pen0, Left_0, Top_A, Right_0, Top_A)
e.Graphics.DrawLine(Pen0, Left_0, Top_A + Height_A, Right_0, Top_A + +Height_A)
e.Graphics.DrawLine(Pen0, Left_0, Top_A + 3 * Height_A, Right_0, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Left_0, Top_A, Left_0, Top_A + +3 * Height_A)
e.Graphics.DrawLine(Pen0, Right_0, Top_A, Right_0, Top_A + +3 * Height_A)
End If
Left_1 = Left_0 + 30
Left_2 = Left_1 + 40
Left_3 = Left_2 + 60
Left_4 = Left_3 + 50
Left_5 = Left_4 + 50
Left_6 = Left_5 + 50
Left_7 = Left_6 + 50
Left_8 = Left_7 + 50
Left_9 = Left_8 + 475
Left_10 = Left_9 + 40
Left_11 = Left_10 + 55
Left_12 = Left_11 + 40
Left_13 = Left_12 + 55
长江支流 2006-02-20
  • 打赏
  • 举报
回复
没用过,如果你用.NET的就是设置
printDocument.DefaultPageSettings.Landscape = True
wudipaopao 2006-02-20
  • 打赏
  • 举报
回复
横向打印吧?

printDocument.DefaultPageSettings.Landscape = True 横向
printDocument.DefaultPageSettings.Landscape = False 综向
youlinga 2006-02-18
  • 打赏
  • 举报
回复
printDocument.DefaultPageSettings.Landscape = True
lidong6 2006-02-18
  • 打赏
  • 举报
回复
好像不是这么回事吧,打印机只有下一页的概念(HasMorePages),没有纵向换页横向换页的问题啊.

如果你要实现横向换页,那你用代码控件第二页是横向的页就可以了.

16,555

社区成员

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

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