Vb.net 如何使用e.HasMorePages For Each
我使用e.HasMorePages和代码Vb.net 如何使用e.HasMorePages For Each,vb.net,Vb.net,我使用e.HasMorePages和代码 For x As Integer = RowNo To dgv.Rows.Count - 1 Dim mypen As New Pen(Color.Black, 6) e.Graphics.DrawString(dgv.Rows(x - 1).Cells(0).Value.ToString(), f, Brushes.Black, 645, yElementy) If RowNo Mod 6 = 0 Then R
For x As Integer = RowNo To dgv.Rows.Count - 1
Dim mypen As New Pen(Color.Black, 6)
e.Graphics.DrawString(dgv.Rows(x - 1).Cells(0).Value.ToString(), f, Brushes.Black, 645, yElementy)
If RowNo Mod 6 = 0 Then
RowNo += 1
e.HasMorePages = True
Exit For
End If
RowNo += 1
Next
如何将e.HasMorePages与代码一起使用
For Each myRow In dtn.Rows
ListView1.Items.Add(n + ListView1.Items.Count + 1)
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myRow.Item(13).ToString())
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myRow.Item(5).ToString())
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myRow.Item(14).ToString())
'i want to add here
Next
典型布局:计数变量(类级别),用于记住我们在项目打印中的位置。我喜欢用
列表(字符串)
进行循环和打印。在printPage事件中,您需要为将记录打印到的行(y轴)设置一个变量,并在每次迭代中递增该变量。因为它是基于图形的,所以您也可以使用结构,并使用对象将内容打印到它,以进行文本包装和布局
我头脑中的例子——未经测试
Public Class Form1'在此处输入您的表单名称
私有计数为整数
作为整数的私有行
私有子打印页面(…)句柄。。。
行=从顶部开始的100'起点
使用p作为新画笔(画笔.Bisque)“自配置图形对象”
“如果我们必须转到下一页,我们使用这里的变量来知道我们在哪里
Dim rowCount=dg.Rows.Count-1
对于i作为整数=计数到行计数
e、 绘图字符串({value},p,Font,x,y)
行+=16'基本上是字体高度和间距
如果行=e.MarginBounds.Bottom-20,则
e、 HasMorePages=True
如果我数数,那么“我们是在最后一排吗?”?
我记得我们在哪里停下来了
退出潜艇,因为此事件将再次触发,我们需要重新开始
如果结束
如果结束
下一个
终端使用
端接头
'...
末级
公共类frmTestHasMorePages
Dim Font12 As Font = New Drawing.Font("Arial", 12, FontStyle.Regular)
Dim Font8 As Font = New Drawing.Font("Arial", 8, FontStyle.Regular)
Dim sBrush As Drawing.Brush
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Static count As Integer
Static topMargin As Integer = 50
Static line As Integer
Static s, z As Integer
Dim linesPerPage = 65
Dim lineCount = 350
Static totalpages As Integer = IIf(lineCount Mod linesPerPage = 0, (lineCount / linesPerPage), (lineCount / linesPerPage) + 1)
sBrush = Brushes.Black
Dim pageBottom = e.PageBounds.Bottom
For i As Integer = count To lineCount
If z > lineCount Then
sBrush = Brushes.Blue
e.Graphics.DrawString("Page " & s + 1 & "/" & totalpages, Font8, sBrush, 750, pageBottom - 20)
sBrush = Brushes.Red
e.Graphics.DrawString("End of document ", Font8, sBrush, 50, pageBottom - 20)
e.HasMorePages = False
Exit Sub
End If
e.Graphics.DrawString("Testing hasmorepages with different options " & z, Font12, sBrush, 45, (i * 16) + topMargin)
line += 15
z += 1
If i = linesPerPage AndAlso s <= totalpages Then
e.HasMorePages = True
sBrush = Brushes.Blue
s += 1
e.Graphics.DrawString("Page " & s & "/" & totalpages, Font8, sBrush, 750, pageBottom - 20)
e.Graphics.DrawString("Continued...", Font8, sBrush, 50, pageBottom - 20)
i = 0
If i <> lineCount Then REM if it is the last line to print
Exit Sub
End If
End If
Next
End Sub
Dim Font12 As Font=新绘图.Font(“Arial”,12,FontStyle.REQUALE)
Dim Font8 As Font=新绘图.Font(“Arial”,8,FontStyle.REQUALE)
如图纸所示调暗sBrush。刷子
私有子PrintDocument1u PrintPage(ByVal sender作为对象,ByVal e作为System.Drawing.Printing.PrintPageEventArgs)处理PrintDocument1.PrintPage
静态计数为整数
静态topMargin为整数=50
静态行作为整数
静态s,z为整数
尺寸线尺寸页=65
尺寸线计数=350
整型静态totalpages=IIf(lineCount Mod linesPerPage=0,(lineCount/linesPerPage),(lineCount/linesPerPage)+1)
sBrush=刷子。黑色
Dim pageBottom=e.PageBounds.Bottom
对于i作为整数=计数到行计数
如果z>行数,则
sBrush=刷子。蓝色
e、 Graphics.DrawString(“页面”&s+1&“/”&totalpages,Font8,sBrush,750,页面底部-20)
sBrush=刷子。红色
e、 图形.抽绳(“文件结尾”,Font8,sBrush,50,pageBottom-20)
e、 HasMorePages=False
出口接头
如果结束
e、 Graphics.DrawString(“测试有更多不同选项的页面”&z,Font12,sBrush,45,(i*16)+topMargin)
行+=15
z+=1
如果i=linesPerPage,并且也是s,那么您希望如何处理代码中的e.HasMorePages
?e
是事件的一部分,不确定您第一次发布的代码来自哪个事件,但我不确定您为什么要在foreach
循环中使用事件值。在打印代码时,您不会向列表视图添加项。这完全没有意义。这个问题出现在使用p时,因为新笔(Pens.Navy)重载解析失败,因为这些参数无法调用可访问的“New”。该程序已经过全面测试,运行良好
Dim Font12 As Font = New Drawing.Font("Arial", 12, FontStyle.Regular)
Dim Font8 As Font = New Drawing.Font("Arial", 8, FontStyle.Regular)
Dim sBrush As Drawing.Brush
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Static count As Integer
Static topMargin As Integer = 50
Static line As Integer
Static s, z As Integer
Dim linesPerPage = 65
Dim lineCount = 350
Static totalpages As Integer = IIf(lineCount Mod linesPerPage = 0, (lineCount / linesPerPage), (lineCount / linesPerPage) + 1)
sBrush = Brushes.Black
Dim pageBottom = e.PageBounds.Bottom
For i As Integer = count To lineCount
If z > lineCount Then
sBrush = Brushes.Blue
e.Graphics.DrawString("Page " & s + 1 & "/" & totalpages, Font8, sBrush, 750, pageBottom - 20)
sBrush = Brushes.Red
e.Graphics.DrawString("End of document ", Font8, sBrush, 50, pageBottom - 20)
e.HasMorePages = False
Exit Sub
End If
e.Graphics.DrawString("Testing hasmorepages with different options " & z, Font12, sBrush, 45, (i * 16) + topMargin)
line += 15
z += 1
If i = linesPerPage AndAlso s <= totalpages Then
e.HasMorePages = True
sBrush = Brushes.Blue
s += 1
e.Graphics.DrawString("Page " & s & "/" & totalpages, Font8, sBrush, 750, pageBottom - 20)
e.Graphics.DrawString("Continued...", Font8, sBrush, 50, pageBottom - 20)
i = 0
If i <> lineCount Then REM if it is the last line to print
Exit Sub
End If
End If
Next
End Sub