Public Class Form18
    Private mychart As New VBprinter.Chartlet()
    Private Sub Form18_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '初始数据
        d1.RowCount = 6
        d1.Rows(0).Cells(0).Value = "张三"
        Randomize()
        For i As Integer = 1 To d1.ColumnCount - 1

            d1.Rows(0).Cells(i).Value = System.Math.Round(Rnd() * 100, 0)
        Next
        d1.Rows(1).Cells(0).Value = "李四"

        For i As Integer = 1 To d1.ColumnCount - 1

            d1.Rows(1).Cells(i).Value = System.Math.Round(Rnd() * 100, 0)
        Next
        d1.Rows(2).Cells(0).Value = "王五"
        For i As Integer = 1 To d1.ColumnCount - 1
            Randomize()
            d1.Rows(2).Cells(i).Value = System.Math.Round(Rnd() * 100, 0)
        Next
        d1.Rows(3).Cells(0).Value = "麻六"
        Randomize()
        For i As Integer = 1 To d1.ColumnCount - 1

            d1.Rows(3).Cells(i).Value = System.Math.Round(Rnd() * 100, 0)
        Next
        d1.Rows(4).Cells(0).Value = "小七"
        Randomize()
        For i As Integer = 1 To d1.ColumnCount - 1

            d1.Rows(4).Cells(i).Value = System.Math.Round(Rnd() * 100, 0)
        Next

        d2.RowCount = 7
        Randomize()
        For i As Integer = 0 To d2.RowCount - 1
            d2.Rows(i).Cells(1).Value = System.Math.Round(Rnd() * 100, 0)
        Next
        d2.Rows(0).Cells(0).Value = "张三"
        d2.Rows(1).Cells(0).Value = "李四"
        d2.Rows(2).Cells(0).Value = "王五"
        d2.Rows(3).Cells(0).Value = "麻六"
        d2.Rows(4).Cells(0).Value = "小七"
        d2.Rows(5).Cells(0).Value = "大八"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        myp.InvalidatePreview()
    End Sub

    Private Sub myp_PrintDocument() Handles myp.PrintDocument

        'Dim mycolor(3) As Color
        'mycolor(0) = Color.Red
        'mycolor(1) = Color.Green
        'mycolor(2) = Color.Green
        'mycolor(3) = Color.Black
        'mychart.Breeze = mycolor


        If RadioButton1.Checked = True Then
            ' mychart.ChartType = VBprinter.Chartlet.ChartTypes.Bar
            mychart.AppearanceStyle = VBprinter.Chartlet.AppearanceStyles.Bar_2D_Aurora_FlatCrystal_NoBorder
            mychart.ChartTitle.Text = "柱状图打印测试"
        ElseIf RadioButton2.Checked = True Then
            'mychart.ChartType = VBprinter.Chartlet.ChartTypes.Pie
            mychart.AppearanceStyle = VBprinter.Chartlet.AppearanceStyles.Pie_2D_Aurora_GlassCrystal_WhiteBorder
            mychart.ChartTitle.Text = "饼图打印测试"
        ElseIf RadioButton3.Checked = True Then
            'mychart.ChartType = VBprinter.Chartlet.ChartTypes.Line
            mychart.AppearanceStyle = VBprinter.Chartlet.AppearanceStyles.Line_3D_Aurora_GlassCrystalNone_NoBorder
            mychart.ChartTitle.Text = "折线图打印测试"
        End If
        If CheckBox1.Checked = True Then
            mychart.ChartTitle.Text = mychart.ChartTitle.Text & "(3D效果)"
            mychart.Dimension = VBprinter.Chartlet.ChartDimensions.Chart3D
        Else
            mychart.Dimension = VBprinter.Chartlet.ChartDimensions.Chart2D
        End If
        ' mychart.Fill.ColorStyle = VBprinter.Chartlet.ColorStyles.Breeze
        'mychart.Stroke.ColorStyle = VBprinter.Chartlet.ColorStyles.Breeze
        mychart.YLabels.UnitText = "分数"

        mychart.Colorful = False
        myp.NewPage()
        myp.DrawText("用Chartlet图表组件打印图表，先打印第1个表格的内容，紧接再以图表的形式打印第1个表格", New Font("黑体", 25))
        myp.NewRow(myp.LastDrawTextHeight)

        d1.DefaultCellStyle.Padding = New System.Windows.Forms.Padding(5, 1, 1, 1)
        d1.GridColor = Color.Black
        myp.PrintDGV(d1, "第一个表格的内容", New Font("黑体", 18), StringAlignment.Center, "1111", True, True, 6, True, True, 0, 0, True, Nothing)

        mychart.BindChartData(d1)
        Dim myrect As New RectangleF(0, myp.Currenty, myp.PaperPrintWidth, myp.PaperPrintHeight / 3)
        myp.DrawChart(mychart, myrect)
        myp.Currenty = myp.Currenty + myrect.Height
        myp.DrawText("下面输出第2个表格的图表打印结果", New Font("黑体", 12))
        myp.NewRow(myp.LastDrawTextHeight)

        mychart.BindChartData(d2)
        myrect = New RectangleF(0, myp.Currenty, myp.PaperPrintWidth, myp.PaperPrintHeight / 3)
        myp.DrawChart(mychart, myrect)
        myp.Currenty = myp.Currenty + myrect.Height
        myp.DrawText("表格下面还可以输出很多文字,可以图文混 打印", New Font("黑体", 12))
    End Sub

  


End Class