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

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

        '构建需要的数据（表格二），表格一为自动取数
        Dim i As Integer
        Dim j As Integer
        Dim mycol As DataGridViewColumn
        Dim myrow As DataGridViewRow
        Dim rows As Integer
        Dim cols As Integer

        cols = 2
        rows = 258
        D2.ColumnCount = cols
        D2.RowCount = rows
        '加一列按钮列
        For i = 0 To cols - 1
            mycol = D2.Columns(i)
            mycol.HeaderText = "第" + CStr(i + 1) + "列"
        Next
        Dim myco2 As New DataGridViewButtonColumn()
        myco2.HeaderText = "按钮列"
        myco2.Visible = True
        myco2.DefaultCellStyle.BackColor = Color.DarkGray
        D2.Columns.Add(myco2)

        D2.Rows(2).Cells(2).Style.ForeColor = Color.Blue
        D2.Rows(2).Cells(2).Style.Font = New Font("华文行楷", 12, FontStyle.Bold Or FontStyle.Strikeout Or FontStyle.Underline)
        cols = 3

        For i = 0 To cols - 1
            mycol = D2.Columns(i)
            mycol.HeaderText = "第" + CStr(i + 1) + "列"
        Next
        For i = 0 To rows - 1
            myrow = D2.Rows(i)
            For j = 0 To cols - 1
                myrow.Cells(j).Value = "第" + CStr(i + 1) + "行 第" + CStr(j + 1) + "列"
            Next

        Next

        D2.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        D2.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

        D2.Rows(0).Cells(0).Value = "表格2"

        Dim mycolumn As New DataGridViewCheckBoxColumn()

        'D2.Columns(2).CellTemplate
        Dim myco As New DataGridViewImageColumn()
        myco.HeaderText = "图片框"
        myco.Visible = True
        myco.ImageLayout = DataGridViewImageCellLayout.Zoom
        D2.Columns.Add(myco)
        D2.Rows(0).Cells(3).Value = My.Resources.mybmp
        D2.Rows(3).Cells(3).Value = My.Resources.myico

        mycolumn.HeaderText = "复选框"
        mycolumn.Visible = True
        mycolumn.TrueValue = "YES"
        mycolumn.FalseValue = "NO"
        D2.Columns.Add(mycolumn)
        D2.Rows(0).Cells(4).Value = "YES"
        D2.Rows(1).Cells(4).Value = "NO"


        '表格字段名特殊格式设置打印测试
        D1.Columns(1).HeaderCell.Style.ForeColor = Color.Red
        Dim mystyle As FontStyle
        mystyle = FontStyle.Bold + FontStyle.Strikeout + FontStyle.Underline + FontStyle.Italic
        D1.Columns(1).HeaderCell.Style.BackColor = Color.Blue
        D1.Columns(1).HeaderCell.Style.Font = New Font("黑体", 13, mystyle)
        D1.Columns(3).HeaderCell.Style.BackColor = Color.Red
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        DgVprint1.IsShowMessageIfPrinterNotSupportPaper = False
        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 = "用户自定义设置打印"
        DgVprint1.PageFooterLeft = "页脚内容（左边）"
        DgVprint1.PageFooterRight = "页脚内容（右边）"
        DgVprint1.SumColumns = ""
        '在此还可以设置其他属性，当然，也可以DGVPRINT1的悔改窗口中进行设置，效果完全一样的
        'D1.Rows(0).Cells(0).Style.Padding = New System.Windows.Forms.Padding(30)
        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.MainTitle = "以普通表格打印"
        DgVprint1.PageHeaderLeft = "页眉内容（左边）"
        DgVprint1.PageHeaderMiddle = "页眉内容（中间）"
        DgVprint1.PrintType = VBprinter.DGVprint.mytype.GeneralPrint '表示普通表格样式
        '在此还可以设置其他属性，当然，也可以DGVPRINT1的悔改窗口中进行设置，效果完全一样的
        DgVprint1.Print(D1, False)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        DgVprint1.MainTitle = "分栏打印"
        DgVprint1.Alignment = StringAlignment.Center '表格居中
        DgVprint1.PrintType = VBprinter.DGVprint.mytype.MulColsPrint '表多栏样式打印表格
        DgVprint1.Columns = 2 '表示两栏
        DgVprint1.ColumnSpace = 50 '表示栏间距，以1/100厘米为单位
        DgVprint1.LastPageMode = True '表示最后一页将先打印满各栏上边的内容，如果为false则表示最后一页先打印满左边各栏的内容
        DgVprint1.TableHeaderLeft = "表格页眉内容（左边）"
        DgVprint1.TableHeaderMiddle = "表格页眉内容（中边）"
        DgVprint1.TableHeaderRight = "表格页眉内容（右边）"
        '在此还可以设置其他属性，当然，也可以DGVPRINT1的悔改窗口中进行设置，效果完全一样的
        DgVprint1.Print(D2, False)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        DgVprint1.MainTitle = "横向跨页打印"
        DgVprint1.Alignment = StringAlignment.Center '表格居中
        DgVprint1.PrintType = VBprinter.DGVprint.mytype.MulPagesPrint '表横向跨页打印（主要用在列很多一页打印不下的情况）
        DgVprint1.TableFooterLeft = "表格页脚内容（左边）"
        DgVprint1.TableFooterMiddle = "表格脚眉内容（中边）"
        DgVprint1.TableFooterRight = "表格页脚内容（右边）"
        DgVprint1.FixedCols = 2 '左边的固定列数，跨页打印时，这些列每页都会打印
        '在此还可以设置其他属性，当然，也可以DGVPRINT1的悔改窗口中进行设置，效果完全一样的
        DgVprint1.Print(D1, False)
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        DgVprint1.MainTitle = "工资条形式打印"
        DgVprint1.PrintType = VBprinter.DGVprint.mytype.GZTPrint '工资条样式打印
        DgVprint1.LineSpace = 50 '每项工资条之间的间距，以1/100厘米为单位
        DgVprint1.PrintZero = False '不打印内容为零值或为空的工资项
        DgVprint1.Print(D1, False)
    End Sub


    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        '使用方案文件进行打印
        '即，控件自动从方案文件中读取全部打印参数进行打印

        Dim mypath As String
        mypath = My.Computer.FileSystem.GetParentPath(Application.ExecutablePath)
        If Microsoft.VisualBasic.Right(mypath, 1) <> "\" Then
            mypath = mypath + "\"
        End If
        mypath = mypath + "第一个打印方案.fa"
        If My.Computer.FileSystem.FileExists(mypath) = False Then
            MsgBox("打印方案文件[" & mypath & "]不存在,程序使用当前设置进行打印")
        End If
        DgVprint1.Print(D1, False, mypath)

    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        '不显示打印预览窗口,直接打印到打印机
        '本功能为3.3版新增加的功能,由于测试条件有限,只在虚拟打印机中试过,未在真实打印机中测试
        '如果本功能不能实现,请与我联系,谢谢
        DgVprint1.IsImmediatePrint = True '要直接打印到打印机,要将此参数设置为TRUE
        DgVprint1.IsImmediatePrintShowPrintDialog = True '要显示打印机选择对话框
        DgVprint1.MainTitle = "直接发送到打印机打印(横向跨页打印)"
        DgVprint1.Alignment = StringAlignment.Center '表格居中
        DgVprint1.PrintType = VBprinter.DGVprint.mytype.MulPagesPrint '表横向跨页打印（主要用在列很多一页打印不下的情况）
        DgVprint1.TableFooterLeft = "表格页脚内容（左边）"
        DgVprint1.TableFooterMiddle = "表格脚眉内容（中边）"
        DgVprint1.TableFooterRight = "表格页脚内容（右边）"
        DgVprint1.FixedCols = 2 '左边的固定列数，跨页打印时，这些列每页都会打印
        DgVprint1.Print(D1, False) '也可用dgvprint1.print(d1,true),此时会显示一个打印参数设置窗口
        DgVprint1.IsImmediatePrint = False '复原
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        '测试3.5版新功能，分组打印
        DgVprint2.MainTitle = "分组打印测试（3.5版新功能）按联系人姓名分组，每组换新页打印，不添加行号"
        DgVprint2.SubTitle = "另外本控件还有分组汇总功能，由于测试条件有限，在此不再测试，您不防一试"
        DgVprint2.Alignment = StringAlignment.Center '表格居中
        DgVprint2.PrintType = VBprinter.DGVprint.mytype.GeneralPrint  '普通表格
        DgVprint2.TableFooterLeft = "表格页脚内容（左边）"
        DgVprint2.TableFooterMiddle = "表格脚眉内容（中边）"
        DgVprint2.TableFooterRight = "表格页脚内容（右边）"
        DgVprint2.SortColumn = "联系人姓名"
        DgVprint2.GroupColumn = "联系人姓名"
        DgVprint2.GroupNewPage = True '新组换新页打印
        DgVprint2.IsAddRowID = False '不添加行号
        DgVprint2.IsGroupNewRowID = True '新组行号从1开始重新编号,由于isaddrowid为FALSE，此处也就没有作用了
        DgVprint2.PaperLandscape = True '纵向打印
        DgVprint2.Print(D1, False) '也可用dgvprint1.print(d1,true),此时会显示一个打印参数设置窗口

    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        '测试3.5版新功能，分组汇总加行号打印
        DgVprint3.MainTitle = "分组打印测试（3.5版新功能）按联系人姓名分组汇总邮政编码列，每组换新页打印，且添加行号，行号每组从1开始重新编号"
        DgVprint3.SubTitle = "您还可以改为分栏打印或跨页打印工资条打印试试，怎么样，本功能够强大吧"
        DgVprint3.Alignment = StringAlignment.Center '表格居中
        DgVprint3.PrintType = VBprinter.DGVprint.mytype.GeneralPrint  '普通表格
        DgVprint3.TableFooterLeft = "表格页脚内容（左边）"
        DgVprint3.TableFooterMiddle = "表格脚眉内容（中边）"
        DgVprint3.TableFooterRight = "表格页脚内容（右边）"
        DgVprint3.SortColumn = "联系人姓名" '只能有一列（注意，此处是列的名称而不是显示的名称）
        DgVprint3.GroupColumn = "联系人姓名" '只能有一列（注意，此处是列的名称而不是显示的名称）
        DgVprint3.SumColumns = "邮政编码" '如果要汇总多列的话，可用英文的分号连接起来（注意，此处是列的名称而不是显示的名称）
        DgVprint3.GroupNewPage = True '新组换新页打印
        DgVprint3.IsAddRowID = True '添加行号
        DgVprint3.IsGroupNewRowID = True '新组行号从1开始重新编号
        DgVprint3.PaperLandscape = True '纵向打印
        DgVprint3.Print(D1, False) '也可用dgvprint1.print(d1,true),此时会显示一个打印参数设置窗口

    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        '测试3.5版新功能，分组汇总加行号打印,是另一种
        Dim dgvprint4 As New VBprinter.DGVprint() '直接创建一个新的
        dgvprint4.MainTitle = "分组打印测试（3.5版新功能）按联系人姓名分组汇总邮政编码列，每组连续打印，且添加行号，行号每组从1开始重新编号"
        dgvprint4.SubTitle = "您还可以改为分栏打印或跨页打印工资条打印试试，怎么样，本功能够强大吧"
        dgvprint4.Alignment = StringAlignment.Center '表格居中
        dgvprint4.PrintType = VBprinter.DGVprint.mytype.GeneralPrint  '普通表格
        dgvprint4.TableFooterLeft = "表格页脚内容（左边）"
        dgvprint4.TableFooterMiddle = "表格脚眉内容（中边）"
        dgvprint4.TableFooterRight = "表格页脚内容（右边）"
        dgvprint4.SortColumn = "联系人姓名" '只能有一列（注意，此处是列的名称而不是显示的名称）
        dgvprint4.GroupColumn = "联系人姓名" '只能有一列（注意，此处是列的名称而不是显示的名称）
        dgvprint4.SumColumns = "邮政编码" '如果要汇总多列的话，可用英文的分号连接起来（注意，此处是列的名称而不是显示的名称）
        dgvprint4.GroupNewPage = False '每组连续打印
        dgvprint4.IsAddRowID = True '添加行号
        dgvprint4.IsGroupNewRowID = True '新组行号从1开始重新编号
        dgvprint4.PaperLandscape = True '纵向打印
        dgvprint4.Print(D1, False) '也可用dgvprint1.print(d1,true),此时会显示一个打印参数设置窗口
        dgvprint4.Dispose()
        dgvprint4 = Nothing
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        Dim dgvprint4 As New VBprinter.DGVprint() '直接创建一个新的
        dgvprint4.MainTitle = "分组打印测试（3.5版新功能）按联系人姓名分组，不进行汇总，每组连续打印，且添加行号，行号连续编号"
        dgvprint4.SubTitle = "您还可以改为分栏打印或跨页打印工资条打印试试，怎么样，本功能够强大吧"
        dgvprint4.Alignment = StringAlignment.Center '表格居中
        dgvprint4.PrintType = VBprinter.DGVprint.mytype.GeneralPrint  '普通表格
        dgvprint4.TableFooterLeft = "表格页脚内容（左边）"
        dgvprint4.TableFooterMiddle = "表格脚眉内容（中边）"
        dgvprint4.TableFooterRight = "表格页脚内容（右边）"
        dgvprint4.SortColumn = "联系人姓名" '只能有一列（注意，此处是列的名称而不是显示的名称）
        dgvprint4.GroupColumn = "联系人姓名" '只能有一列（注意，此处是列的名称而不是显示的名称）
        dgvprint4.SumColumns = "" '不汇总
        dgvprint4.GroupNewPage = False '每组连续打印
        dgvprint4.IsAddRowID = True '添加行号
        dgvprint4.IsGroupNewRowID = False '行号连续（每组不重新编号）
        dgvprint4.PaperLandscape = True '纵向打印
        dgvprint4.Print(D1, False) '也可用dgvprint1.print(d1,true),此时会显示一个打印参数设置窗口
        dgvprint4.Dispose()
        dgvprint4 = Nothing
    End Sub



   
End Class