打印换页问题
我的页面是一行行写出来的,现在要控制它自动换页,请 问如何实现,我 的代码如下:
line = Space(12) & "我的爸爸"
yPos = topMargin + (1 * printFontDetail.GetHeight(ev.Graphics))
yposadd = 1 * printFontDetail.GetHeight(ev.Graphics)
ev.Graphics.DrawString(line, PrintFontTitle, Brushes.Black, leftMargin, yPos, New StringFormat)
....
....
For i = 1 To GridDetail.Rows - 1
line = GridDetail.get_TextMatrix(i, 1) & Space(15) & GridDetail.get_TextMatrix(i, 2) & Space(5) & Format(GridDetail.get_TextMatrix(i, 3), "long date") & Space(2) & Format(GridDetail.get_TextMatrix(i, 3), "long time") & Space(5) & GridDetail.get_TextMatrix(i, 4) & Space(8) & Format(CDec(GridDetail.get_TextMatrix(i, 5)), "####0.00")
summoney = summoney + CDec(GridDetail.get_TextMatrix(i, 5))
yPos = topMargin + ((i + 15) * printFontDetail.GetHeight(ev.Graphics))
ev.Graphics.DrawString(line, printFontDetail, Brushes.Black, leftMargin, yPos, New StringFormat)
...
谢谢!
问题点数:100、回复次数:6Top
1 楼swzlxm(守望者)回复于 2005-01-24 16:05:28 得分 20
哦,是使用事件打印的;
有个属性: E.HASMOREPAGE = TRUE;(可能属性名写错了)
这样这个事件就会再执行一次,不要打印的时候就设为FALSETop
2 楼GHOSTSEA(GHOST SEA)回复于 2005-01-24 16:10:37 得分 0
语法不懂,但是还要帮你顶啊~~~~~Top
3 楼luoye2002(落叶2002)回复于 2005-01-24 16:23:12 得分 0
谁能 具体点,针对我这个例子的
Top
4 楼landlordh(work wonders)回复于 2005-01-24 16:23:42 得分 30
给你个例子
http://blog.csdn.net/landlordh/archive/2004/11/23/192119.aspxTop
5 楼weixinzhu(我想哭,可是我没有眼泪)回复于 2005-01-24 16:26:40 得分 50
Private Sub printpageeventhandler(ByVal obj As System.Object, ByVal ev As PrintPageEventArgs)
Dim x As Single = 0 '行排列的数量
Dim y As Single = 0 '列排列的数量
Dim scale1 As Single = 0 '比例因子1
Dim scale2 As Single = 0 '比例因子2
Dim scale3 As Single = 0 '比例因子3
Dim scaleRow As Integer = 0 '面图中的行数
Dim scaleCol As Integer = 0 '面图中的列数
Dim rectborderRow As Integer = 0 '由贝的行数确定巨型的边长
Dim rectborderCol As Integer = 0 '由贝的列数确定巨型的边长
Dim papername As String '选择纸张的类型
Dim dsPaper As New DataSet()
Dim g As Graphics
g = ev.Graphics
pagecount = pagecount + 1 '页数控制变量
If Microsoft.VisualBasic.Left(ev.PageSettings.PaperSize.PaperName, 2) = "A4" Then
pageHeight = 787 - 10 - 20
pageWidth = 1130 - 10
End If
If Microsoft.VisualBasic.Left(ev.PageSettings.PaperSize.PaperName, 2) = "B4" Then
pageHeight = 996 - 25 - 30
pageWidth = 1418 - 10
End If
'页面的高度
' pageHeight = ev.MarginBounds.Bottom - 10 - 30 '可以加到60 ,去掉底部的注释10,去掉顶部的注释20
'页面的宽度
' pageWidth = ev.MarginBounds.Right - 10 ' + 30
'选择纸张的类型
papername = ev.PageSettings.PaperSize.PaperName()
Getdata("select * from con_mapset where papername=left('" & papername & "',2) and baycount='" & totalBay & "'", dsPaper)
'放缩比例因子
If Len(Me.txt_percent.Text) > 0 Then
Try
expandPercent = CType(Me.txt_percent.Text, Integer) / 100
Catch
MsgBox("请输入数字!", MsgBoxStyle.OKOnly, "提示")
Exit Sub
End Try
End If
'计算矩形的边长---贝层数+4(两层贝列,一层空格,一层空格大小作为写bay标志),贝列数+1(一列贝层)=面图上每个bay分配的面积大小 'RectBorder = Floor(Sqrt(pageHeight * pageWidth / (ship_bay_count * (maxrow_board + maxrow_cabin + 4) * (ship_col_count + 1) * expandPrecent)))
'计算面图中贝的行数和列数
scaleRow = dsPaper.Tables(0).Rows(0).Item("row")
scaleCol = dsPaper.Tables(0).Rows(0).Item("col")
'计算矩形的边长
rectborderRow = (pageHeight / scaleRow) / (maxrow_board + maxrow_cabin + 4) ' * expandpercent
rectborderCol = (pageWidth / scaleCol) / (ship_col_count + 1) ' * expandPercent
If rectborderRow > rectborderCol Then
RectBorder = Floor(rectborderCol)
Else
RectBorder = Floor(rectborderRow)
End If
'RectBorder = RectBorder * expandPercent
'RectBorder = 20
'确保边长是偶数
If RectBorder Mod 2 = 1 Then
RectBorder = RectBorder - 1
End If
'放缩
If Len(Me.txt_percent.Text) > 0 Then
'边厂小于最小边长
If RectBorder < minRectBorder Then
RectBorder = minRectBorder * expandPercent
End If
'边厂大于最大边长
If RectBorder > maxRectBorder Then
RectBorder = maxRectBorder * expandPercent
End If
'边长处于合适边长
If RectBorder >= minRectBorder And RectBorder <= maxRectBorder Then
RectBorder = RectBorder * expandPercent
End If
Else
If RectBorder < minRectBorder Then
RectBorder = minRectBorder
'MsgBox("请重新输入放缩比例或者另选纸类型!", MsgBoxStyle.OKOnly, "提示")
'Exit Sub
End If
If RectBorder > maxRectBorder Then
RectBorder = maxRectBorder
End If
End If
'边长已经确定 由边长判断是否有两页
faceColCount = Floor(pageWidth / ((ship_col_count + 1) * RectBorder)) '一行放的贝数
faceRowCount = Floor(pageHeight / ((maxrow_board + maxrow_cabin + 4) * RectBorder)) '面图上放贝的层数
firstFaceBayCount = faceColCount * faceRowCount
If totalBay <= firstFaceBayCount Then
'只需要一页
con_ship_facemap_print(g)
ev.HasMorePages = False
Else
'需要多页 第二页
'If pagecount Mod 2 = 1 Then
' '打印第一页
' con_ship_facemap_print_first(g, firstFaceBayCount)
' ev.HasMorePages = True
'End If
'If pagecount Mod 2 = 0 Then
' '打印第二页
' con_ship_facemap_print_first(g, totalBay - firstFaceBayCount)
' ev.HasMorePages = False
'End If
If pagecount Mod 5 = 1 Then
'打印第一页
con_ship_facemap_print_first(g, firstFaceBayCount)
ev.HasMorePages = True
End If
If pagecount Mod 5 = 2 Then
'打印第二页
If totalBay <= 2 * firstFaceBayCount Then
con_ship_facemap_print_first(g, totalBay - firstFaceBayCount)
ev.HasMorePages = False
Else
con_ship_facemap_print_first(g, firstFaceBayCount)
ev.HasMorePages = True
End If
End If
If pagecount Mod 5 = 3 Then
'打印第三页
If totalBay <= 3 * firstFaceBayCount Then
con_ship_facemap_print_first(g, totalBay - 2 * firstFaceBayCount)
ev.HasMorePages = False
Else
con_ship_facemap_print_first(g, firstFaceBayCount)
ev.HasMorePages = True
End If
End If
If pagecount Mod 5 = 4 Then
'打印第四页
If totalBay <= 4 * firstFaceBayCount Then
con_ship_facemap_print_first(g, totalBay - 3 * firstFaceBayCount)
ev.HasMorePages = False
Else
con_ship_facemap_print_first(g, firstFaceBayCount)
ev.HasMorePages = True
End If
End If
If pagecount Mod 5 = 0 Then
'打印第五页
con_ship_facemap_print_first(g, totalBay - 4 * firstFaceBayCount)
ev.HasMorePages = False
End If
End If
End SubTop
6 楼weixinzhu(我想哭,可是我没有眼泪)回复于 2005-01-24 16:26:59 得分 0
Private Sub btn_pagesetup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_pagesetup.Click
Try
Dim psdlg As New PageSetupDialog()
psdlg.AllowMargins = False
psdlg.AllowOrientation = False
' If Me.storedpagesettings Is System.DBNull.Value Then
Me.storedpagesettings = New PageSettings()
' End If
psdlg.PageSettings = Me.storedpagesettings
psdlg.PageSettings.Landscape = True
psdlg.ShowDialog()
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub btn_printpreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_printpreview.Click
Try
pagecount = 0
ship_bay_count = totalBay '船的贝数
Dim pd As New PrintDocument
' pd.DefaultPageSettings.Landscape = True
AddHandler pd.PrintPage, AddressOf printpageeventhandler
If (Me.storedpagesettings Is System.DBNull.Value) = False Then
pd.DefaultPageSettings = Me.storedpagesettings
End If
pd.DefaultPageSettings.Landscape = True
Dim dlg As New PrintPreviewDialog
dlg.Document = pd
dlg.ShowDialog()
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub btn_enter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_enter.Click
Try
pagecount = 0
ship_bay_count = totalBay '船的贝数
Dim pd As New PrintDocument
' pd.DefaultPageSettings.Landscape = True
AddHandler pd.PrintPage, AddressOf printpageeventhandler
' pd.printpage=pd.printpage+new PrintPageEventHandler(me.printpageeventhandler);
If (Me.storedpagesettings Is System.DBNull.Value) = False Then
pd.DefaultPageSettings = Me.storedpagesettings
End If
pd.DefaultPageSettings.Landscape = True
Dim dlg As New PrintDialog
dlg.Document = pd
dlg.AllowSelection = True
dlg.AllowSomePages = True
Dim result As DialogResult
result = dlg.ShowDialog
If (result = DialogResult.OK) Then
pd.Print()
End If
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End SubTop




