Public Class Form17
    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.RowCount = Me.NorthwindDataSet.客户.Rows.Count
        d1.ColumnCount = Me.NorthwindDataSet.客户.Columns.Count
        For i As Integer = 0 To d1.RowCount - 1
            For j As Integer = 0 To d1.ColumnCount - 1
                d1.Rows(i).Cells(j).Value = Me.NorthwindDataSet.客户.Rows(i).Item(j)
            Next
        Next
        For j As Integer = 0 To d1.ColumnCount - 1
            d1.Columns(j).HeaderText = Me.NorthwindDataSet.客户.Columns(j).Caption
        Next

        d1.Rows(2).Cells(3).Style.BackColor = Color.Green
        d1.MergeCell(4, 6, 5, 7)

        d1.MergeCell(2, 5, 3, 3)
        d1.MergeCell(8, 15, 3, 8)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '合并选中单元格
        d1.MergeSelectedCell()

    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, True, "", d1.ColHeaderTreeView)
    End Sub

   

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim myp As New VBprinter.VB2008Print
        myp.NewDoc()
        myp.NewPage(True)
        myp.PrintDGV(d1, "以普通表格打印多表头组件", New Font("黑体", 18, FontStyle.Bold), StringAlignment.Center, "1111", True, False, 0, True, True, 0, 0, False, d1.ColHeaderTreeView)
        myp.EndDoc("多表头组件打印预览")
        myp.Dispose()
        myp = Nothing
    End Sub

 





    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        d1.CancelMergeSelectedCell()
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        For i As Integer = 0 To d1.SelectedCells.Count - 1
            d1.SelectedCells(i).Style.Font = New Font("黑体", 18, FontStyle.Bold)
            d1.SelectedCells(i).Style.WrapMode = DataGridViewTriState.True
        Next

    End Sub

   
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim myexport As New VBprinter.ExportDGV
        myexport.Title = "多表头组件导出Excel测试"
        myexport.OpenFile = True
        myexport.ExportDGV(d1)
        myexport.Dispose()
        myexport = Nothing
    End Sub
End Class