Public Class Form15
    Dim printtype As Integer
   
    Private Sub Form15_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.客户TableAdapter.Fill(Me.NorthwindDataSet.客户)
        D1.DataSource = Me.NorthwindDataSet.客户

        
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        DgVprint1.PrintType = VBprinter.DGVprint.mytype.GeneralPrint
        DgVprint1.Alignment = StringAlignment.Center '表格居中
        DgVprint1.PaperMargins = New System.Drawing.Printing.Margins(150, 140, 150, 150)
        DgVprint1.SubTitle = "表格小标题"
        DgVprint1.MainTitle = "表格页脚每页重复打印测试(仅需将控件的IsDrawTableFooterEveryPage属性设置为True即可)"
        DgVprint1.TableFooterLeft = "表格页脚内容（左边）"
        DgVprint1.TableFooterRight = "表格页脚内容（右边）"
        DgVprint1.IsDrawTableFooterEveryPage = True '需要将此属性设置为True
        DgVprint1.Print(D1, True)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        DgVprint1.PrintType = VBprinter.DGVprint.mytype.GeneralPrint
        DgVprint1.Alignment = StringAlignment.Center '表格居中
        DgVprint1.SubTitle = "表格小标题"
        DgVprint1.MainTitle = "表格页脚每页重复打印测试(仅需将控件的IsDrawTableFooterEveryPage属性设置为True即可)"
        DgVprint1.TableFooterLeft = "表格页脚内容（左边）"
        DgVprint1.TableFooterRight = "表格页脚内容（右边）"
        DgVprint1.IsDrawTableFooterEveryPage = True '需要将此属性设置为True
        DgVprint1.PrintType = VBprinter.DGVprint.mytype.GeneralPrint '表示普通表格样式
        DgVprint1.Print(D1, False)
    End Sub

    
    Private Sub myp_PrintDocument() Handles myp.PrintDocument
        '第二种方法,直接在PrintDocumnt事件中写代码
        myp.NewPage()
        Myprint()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        '第一种方法,用NewDoc与EndDoc实现
        myp.NewDoc()
        myp.NewPage()
        Myprint()
        myp.EndDoc()
    End Sub

    Private Sub Myprint()

        myp.IsDrawTableFooterEveryPage = True
        myp.PrintDGV(D1, "表格页脚每页重复打印测试(仅需将控件的IsDrawTableFooterEveryPage属性设置为True即可)", New Font("黑体", 18, FontStyle.Bold), "表格小标题,如果没有,可以设置为空", New Font("宋体", 12), StringAlignment.Center, "1111", True, False, New Font("黑体", 12), "这是表格的页眉左边", "表格页眉中间", "页眉右边", New Font("宋体", 13), "表格页脚(左边)", "表格页脚(中间)", "表格页脚(右边)", 6, True)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        '第二种方法
        myp.InvalidatePreview()
    End Sub
End Class