Public Class Form5
    Private myprintstyle As Integer = 0
    Private Sub 订单BindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.订单BindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.NorthwindDataSet)

    End Sub

    Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: 这行代码将数据加载到表“NorthwindDataSet.供应商”中。您可以根据需要移动或移除它。
        'TODO: 这行代码将数据加载到表“NorthwindDataSet.订单”中。您可以根据需要移动或移除它。
        Me.订单TableAdapter.Fill(Me.NorthwindDataSet.订单)
        Me.供应商TableAdapter.Fill(Me.NorthwindDataSet.供应商)




        d1.Columns(1).HeaderCell.Style.BackColor = Color.Blue
        d1.Columns(1).HeaderCell.Style.ForeColor = Color.Red
        d1.Columns(1).HeaderCell.Style.Font = New Font("黑体", 13, FontStyle.Bold)
        d1.Columns(3).HeaderCell.Style.BackColor = Color.Red

        d1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
        'd2.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
    End Sub

    Private Sub MulHeaderDataGridView_ClientSizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles d1.ClientSizeChanged
    End Sub

    Private Sub MulHeaderDataGridView_ColumnDisplayIndexChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs) Handles d1.ColumnDisplayIndexChanged
        'MsgBox(e.Column.HeaderText & e.Column.DisplayIndex)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        d2.Columns(CInt(TextBox1.Text)).Visible = Not d1.Columns(CInt(TextBox1.Text)).Visible
    End Sub



    Private Sub VB2008Print1_HeaderFooterOut(ByVal pages As Integer, ByVal curpage As Integer) Handles VB2008Print1.HeaderFooterOut
        VB2008Print1.PrintFooter("608研究所", "第 " & CStr(curpage) & " 页 共 " & CStr(pages) & " 页", "")
        VB2008Print1.PrintHeader("中国", "湖南 株洲", "", New Font("华文行楷", 10, FontStyle.Bold), Color.Red)
    End Sub

    Private Sub VB2008Print1_PrintDocument() Handles VB2008Print1.PrintDocument

        VB2008Print1.NewPage() '首先要创建新页
        Select Case myprintstyle
            Case 11
                '以普通表格形式按当前显示样式打印表格1
                VB2008Print1.PrintDGV(Me.d1, "完全按表格1当前显示的格式进行打印", New Font("黑体", 18), "表格子标题", New Font("隶书", 13), StringAlignment.Center, "1111", False, False, Nothing, "", "制表日期：2010年11月28日", "", Nothing, "", "", "", 5, True, True, 0, 0, False, d1.ColHeaderTreeView)
            Case 12
                '以缩放致纸张宽度形式按当前显示样式打印表格1
                VB2008Print1.PrintDGV(Me.d1, "以自动缩放到纸张宽度样式打印表格1", New Font("黑体", 18), "小标题", New Font("隶书", 15), StringAlignment.Center, "1111", True, True, Nothing, "表格左边面眉", "表格中间页眉", "表格右边页眉", Nothing, "", "制表:游平", "E-main:myyouping@hotmail.com", 5, True, True, 0, 0, True, d1.ColHeaderTreeView)
            Case 13
                '以缩放致纸张宽度形式按当前显示样式打印表格1
                VB2008Print1.PrintDGV(Me.d1, "以自动缩放到纸张宽度样式打印表格1(不打印背景颜色)", New Font("黑体", 18), "小标题", New Font("隶书", 15), StringAlignment.Center, "1111", True, True, Nothing, "表格左边面眉", "表格中间页眉", "表格右边页眉", Nothing, "", "制表:游平", "E-main:myyouping@hotmail.com", 5, True, False, 0, 0, True, d1.ColHeaderTreeView)
            Case 14
                '以缩放致纸张宽度形式按当前显示样式打印表格1
                VB2008Print1.PrintDGV(Me.d1, "以普通表头样式打印表格1", New Font("黑体", 18), "小标题", New Font("隶书", 15), StringAlignment.Center, "1111", True, True, Nothing, "表格左边面眉", "表格中间页眉", "表格右边页眉", Nothing, "", "制表:游平", "E-main:myyouping@hotmail.com", 5, True, False, 0, 0, True)
            Case 15
                '以缩放致纸张宽度形式按当前显示样式打印表格2
                VB2008Print1.PrintDGV(d2, "打印表格2的内容", New Font("黑体", 18), "小标题", New Font("隶书", 15), StringAlignment.Center, "1111", True, True, Nothing, "表格左边面眉", "表格中间页眉", "表格右边页眉", Nothing, "", "制表:游平", "E-main:myyouping@hotmail.com", 5, True, True, 0, 0, True, d2.ColHeaderTreeView)

            Case 21
                '以工资条打印(要打印背景颜色)
                VB2008Print1.PrintDGVgzt(Me.d1, "工资条打印表1(要打印背景颜色,注意,多行表头下以工资条打印,0值或空值总是会打印的,会忽略printzero参数))", New Font("黑体", 18), StringAlignment.Center, "1111", False, True, 0, True, 20, 0, True, 0, 0, True, Me.d1.ColHeaderTreeView)

            Case 22
                '以工资条打印(不要打印背景颜色)
                VB2008Print1.PrintDGVgzt(Me.d1, "工资条打印表1(不要打印背景颜色,注意,多行表头下以工资条打印,0值或空值总是会打印的,会忽略printzero参数)", New Font("黑体", 18), StringAlignment.Near, "1111", False, True, 0, True, 20, 0, False, 0, 0, True, Me.d1.ColHeaderTreeView)
            Case 31
                '二栏打印表1(要打印背景颜色)
                VB2008Print1.PrintDGVColS(d1, 2, "二栏打印表1(要打印背景颜色)", New Font("黑体", 18), 0, 20, "1111", 5, True, True, True, 0, 0, True, d1.ColHeaderTreeView)

            Case 32
                '二栏打印表1(要打印背景颜色)
                VB2008Print1.PrintDGVColS(d1, 2, "二栏打印表1(不打印背景颜色)", New Font("黑体", 18), "这是子标题", New Font("华文行楷", 12), Nothing, "制表:游平", "E-Mail:myyouping@hotmail.com", "", 0, 20, "1111", 5, True, True, False, 0, 0, True, d1.ColHeaderTreeView)

            Case 33
                '二栏打印表2
                VB2008Print1.PrintDGVColS(d2, 2, "二栏打印表2(最后一页先打印满左边)", New Font("黑体", 18), "这是子标题", New Font("华文行楷", 12), Nothing, "制表:游平", "E-Mail:myyouping@hotmail.com", "", 0, 20, "1111", 5, True, False, True, 0, 0, True, d2.ColHeaderTreeView)
            Case 41
                '横向跨页打印表1
                VB2008Print1.PrintDGVPages(d1, 1, "横向跨页打印表1(第一列每页重复打印)", New Font("黑体", 18), "子标题", New Font("隶书", 13), StringAlignment.Center, "1111", True, New Font("宋体", 10), "制表:游平", "地址:湖南省 株洲市 215信箱 财务处", "", Nothing, "", "E-Mail:myyouping@hotmail.com", "", 5, True, True, 0, 0, True, d1.ColHeaderTreeView)
            Case 42
                '横向跨页打印表1
                VB2008Print1.PrintDGVPages(d1, 3, "横向跨页打印表1(左边3列每页重复打印,标题行只第一页及该页的跨行页打印)", New Font("黑体", 18), "子标题", New Font("隶书", 13), StringAlignment.Center, "1111", True, New Font("宋体", 10), "制表:游平", "地址:湖南省 株洲市 215信箱 财务处", "", Nothing, "", "E-Mail:myyouping@hotmail.com", "", 5, False, True, 0, 0, True, d1.ColHeaderTreeView)

            Case 43
                '横向跨页打印表1
                VB2008Print1.PrintDGVPages(d1, 4, "横向跨页打印表1(左边4列每页重复打印)", New Font("黑体", 18), "子标题", New Font("隶书", 13), StringAlignment.Center, "1111", True, New Font("宋体", 10), "制表:游平", "地址:湖南省 株洲市 215信箱 财务处", "", Nothing, "", "E-Mail:myyouping@hotmail.com", "", 5, True, True, 0, 0, True, d1.ColHeaderTreeView)

            Case 44
                '横向跨页打印表1
                VB2008Print1.PrintDGVPages(d1, 6, "横向跨页打印表1(左边6列每页重复打印)", New Font("黑体", 18), "子标题", New Font("隶书", 13), StringAlignment.Center, "1111", True, New Font("宋体", 10), "制表:游平", "地址:湖南省 株洲市 215信箱 财务处", "", Nothing, "", "E-Mail:myyouping@hotmail.com", "", 5, True, True, 0, 0, True, d1.ColHeaderTreeView)

            Case 45
                '横赂跨页打印表2
                VB2008Print1.PrintDGVPages(d2, 1, "横向跨页打印表2(第一列每页重复打印)", New Font("黑体", 18), "子标题", New Font("隶书", 13), StringAlignment.Center, "1111", True, New Font("宋体", 10), "制表:游平", "地址:湖南省 株洲市 215信箱 财务处", "", Nothing, "", "E-Mail:myyouping@hotmail.com", "", 5, True, True, 0, 0, True, d2.ColHeaderTreeView)

            Case 51
                '普通加行号打印
                VB2008Print1.PrintDGV(d1, "普通加行号打印表格1", New Font("黑体", 18), "子标题", Nothing, StringAlignment.Center, "1111", True, True, New Font("隶书", 10), "制表:游平", "地址:湖南省株洲市215信箱", "", Nothing, Nothing, Color.Red, Color.Blue, "", True, True, "", System.ComponentModel.ListSortDirection.Ascending, "", True, "", "", "", 5, True, True, True, 0, 0, d1.ColHeaderTreeView)
            Case 52
                '普通按运货费用汇总
                VB2008Print1.PrintDGV(d1, "普通汇总打印(按运货费用汇总,按地区分组,每组连续打印)", New Font("黑体", 18), "子标题", Nothing, StringAlignment.Center, "1111", True, True, New Font("隶书", 10), "制表:游平", "地址:湖南省株洲市215信箱", "", Nothing, Nothing, Color.Red, Color.Yellow, "运货费用", False, True, "地区", System.ComponentModel.ListSortDirection.Ascending, "地区", False, "", "中国航空动力机械研究所", "", 5, True, True, True, 0, 0, d1.ColHeaderTreeView)
            Case 53
                '普通按运货费用汇总
                VB2008Print1.PrintDGV(d1, "普通汇总打印(按运货费用汇总,按地区分组,添加行号,每组换新页打印)", New Font("黑体", 18), "子标题", Nothing, StringAlignment.Center, "1111", True, True, New Font("隶书", 10), "制表:游平", "地址:湖南省株洲市215信箱", "", Nothing, Nothing, Color.Red, Color.Yellow, "运货费用", True, True, "地区", System.ComponentModel.ListSortDirection.Ascending, "地区", True, "", "中国航空动力机械研究所", "", 5, True, True, True, 0, 0, d1.ColHeaderTreeView)
            Case 54
                '两栏分组汇总加行号打印(按运货费汇总,按地区分组,加行号)
                VB2008Print1.PrintDGVColS(d1, 2, "两栏分组汇总加行号打印(按运货费汇总,按地区分组,每组换新页打印,加行号", New Font("黑体", 18), "子标题", Nothing, New Font("隶书", 10), "制表:游平", "地址:湖南省株洲市215信箱", "", Nothing, Nothing, Color.Red, Color.Yellow, "运货费用", True, True, "地区", System.ComponentModel.ListSortDirection.Ascending, "地区", True, "", "中国航空动力机械研究所", "", 50, "1111", 5, True, True, True, True, True, 0, 0, d1.ColHeaderTreeView)
            Case 100
                '混合打印

                VB2008Print1.PrintDGVColS(d1, 2, "混合打印,先二栏打印表1(要打印背景颜色)", New Font("黑体", 18), 0, 20, "1111", 5, True, True, True, 0, 0, True, d1.ColHeaderTreeView)
                '再输出文字
                VB2008Print1.DrawText(TextBox2.Text)
                VB2008Print1.NewRow(VB2008Print1.LastDrawTextHeight)
                '再输表格
                '普通按运货费用汇总
                VB2008Print1.PrintDGV(d1, "再普通汇总打印(按运货费用汇总,按地区分组,每组连续打印)", New Font("黑体", 18), "子标题", Nothing, StringAlignment.Center, "1111", True, True, New Font("隶书", 10), "制表:游平", "地址:湖南省株洲市215信箱", "", Nothing, Nothing, Color.Red, Color.Yellow, "运货费用", False, True, "地区", System.ComponentModel.ListSortDirection.Ascending, "地区", False, "", "中国航空动力机械研究所", "", 5, True, True, True, 0, 0, d1.ColHeaderTreeView)

        End Select


        'VB2008Print1.PrintDGV(Me.MulHeaderDataGridView, "主标题", New Font("黑体", 18), StringAlignment.Near, "1111", 0, True, True, 0, 0, False, MulHeaderDataGridView.ColHeaderTreeView)

        '以工资条打印

    End Sub




    Private Sub 将第一个表导出成Excel文件ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 将第一个表导出成Excel文件ToolStripMenuItem.Click
        DgVprint1.ExportDGVToExcel(Me.d1, "多表头导出测试", Me.d1.ColHeaderTreeView)
    End Sub

    Private Sub 将第二个表导出成Excel文件ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 将第二个表导出成Excel文件ToolStripMenuItem.Click
        DgVprint1.ExportDGVToExcel(d2, "多表头导出测试", d2.ColHeaderTreeView)
    End Sub

    Private Sub 完全按当前表格格式打印ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 完全按当前表格格式打印ToolStripMenuItem.Click
        myprintstyle = 11
        VB2008Print1.InvalidatePreview()
    End Sub

    Private Sub 自动调整到纸宽宽度ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 自动调整到纸宽宽度ToolStripMenuItem.Click
        myprintstyle = 12
        VB2008Print1.InvalidatePreview()
    End Sub

    Private Sub 不打印背景颜色ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 不打印背景颜色ToolStripMenuItem.Click
        myprintstyle = 13
        VB2008Print1.InvalidatePreview()
    End Sub

    Private Sub 以普通表头不是显示的多行表头打印ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 以普通表头不是显示的多行表头打印ToolStripMenuItem.Click
        myprintstyle = 14
        VB2008Print1.InvalidatePreview()
    End Sub

    Private Sub 打印表格二ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打印表格二ToolStripMenuItem.Click
        myprintstyle = 15
        VB2008Print1.InvalidatePreview()
    End Sub

    Private Sub 工资条打印表1包括背景颜色ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 工资条打印表1包括背景颜色ToolStripMenuItem.Click
        myprintstyle = 21
        VB2008Print1.InvalidatePreview()
    End Sub

    Private Sub 工资条打印表1不包括背景颜色ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 工资条打印表1不包括背景颜色ToolStripMenuItem.Click
        myprintstyle = 22
        VB2008Print1.InvalidatePreview()
    End Sub

    Private Sub 两栏打印表1要打印背景色ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 两栏打印表1要打印背景色ToolStripMenuItem.Click
        myprintstyle = 31
        VB2008Print1.InvalidatePreview()
    End Sub

    Private Sub 两栏打印表1不要打印背景色ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 两栏打印表1不要打印背景色ToolStripMenuItem.Click
        myprintstyle = 32
        VB2008Print1.InvalidatePreview()
    End Sub

    Private Sub 两栏打印表2ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 两栏打印表2ToolStripMenuItem.Click
        myprintstyle = 33
        VB2008Print1.InvalidatePreview()
    End Sub

  
    Private Sub 横向跨页打印表1ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 横向跨页打印表1ToolStripMenuItem.Click
        myprintstyle = 41
        VB2008Print1.InvalidatePreview()
    End Sub

    Private Sub VB2008Print1_QueryDefaultPageSettings(ByRef mypapersize As System.Drawing.Printing.PaperSize, ByRef thePaperMargin As System.Drawing.Printing.Margins, ByRef isPaperLandscape As Boolean) Handles VB2008Print1.QueryDefaultPageSettings
        If myprintstyle > 40 And myprintstyle < 50 Then
            '本程序默认使用横向打印,但跨页打印时,由于表格列比较少,会看不到跨页打印效果(因为在横向纸张时不需要跨页就可以打印完表格)
            '故此时使用纵向打印,以便您可以看到跨页打印的效果
            isPaperLandscape = False '纵向打印
        Else
            isPaperLandscape = True '横向打印
        End If
    End Sub

    Private Sub 横向跨页打印左边3列每页重复打印标题行仅首页打印ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 横向跨页打印左边3列每页重复打印标题行仅首页打印ToolStripMenuItem.Click
        myprintstyle = 42
        VB2008Print1.InvalidatePreview()
    End Sub




    Private Sub 横向跨页打印表2ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 横向跨页打印表2ToolStripMenuItem.Click
        myprintstyle = 45
        VB2008Print1.InvalidatePreview()
    End Sub

    Private Sub 横向跨页打印左边4列每页重复打印ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 横向跨页打印左边4列每页重复打印ToolStripMenuItem.Click
        myprintstyle = 43
        VB2008Print1.InvalidatePreview()
    End Sub

    Private Sub 横向跨页打印左边6列每页重复打印ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 横向跨页打印左边6列每页重复打印ToolStripMenuItem.Click
        myprintstyle = 44
        VB2008Print1.InvalidatePreview()
    End Sub

  
 
    Private Sub 普通加行号打印ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 普通加行号打印ToolStripMenuItem.Click
        myprintstyle = 51
        VB2008Print1.InvalidatePreview()
    End Sub

    Private Sub 普通汇总打印按运货费汇总ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 普通汇总打印按运货费汇总ToolStripMenuItem.Click
        myprintstyle = 52
        VB2008Print1.InvalidatePreview()
    End Sub

    Private Sub 普通汇总加行号打印按运货费汇总ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 普通汇总加行号打印按运货费汇总ToolStripMenuItem.Click
        myprintstyle = 53
        VB2008Print1.InvalidatePreview()
    End Sub

    Private Sub 普通分组汇总加行号打印按运货费汇总按雇员ID分组ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 普通分组汇总加行号打印按运货费汇总按雇员ID分组ToolStripMenuItem.Click
        myprintstyle = 54
        VB2008Print1.InvalidatePreview()
    End Sub


    Private Sub 混合打印ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 混合打印ToolStripMenuItem.Click
        myprintstyle = 100
        VB2008Print1.InvalidatePreview()
    End Sub
End Class