Public Class SimpleReportTest3

    Private Sub SimpleReportTest3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.产品TableAdapter.Fill(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"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim mysp As New VBprinter.SimpleReport()
        Dim mymbfile As String
        mymbfile = My.Application.Info.DirectoryPath & "\" & "第四个打印方案.yp"
        mysp.SetReportDataSource(D1)
        mysp.IsImmediatePrint = False
        mysp.SetReportVar("主标题", TextBox3.Text)
        mysp.SetReportVar("制表", TextBox2.Text)
        mysp.SetReportVar("单位", TextBox1.Text)
        mysp.Print(mymbfile, True, True, True)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim mysp As New VBprinter.SimpleReport()
        Dim mymbfile As String
        mymbfile = My.Application.Info.DirectoryPath & "\" & "第五个打印方案.yp"
        mysp.SetReportDataSource(D1)
        mysp.IsImmediatePrint = False
        mysp.SetReportVar("主标题", TextBox3.Text)
        mysp.SetReportVar("制表", TextBox2.Text)
        mysp.SetReportVar("单位", TextBox1.Text)
        mysp.WindowTitle = "[" & mymbfile & "]打印预览"
        mysp.Print(mymbfile, True, True, True)
    End Sub
End Class