Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Imports System.IO
Imports ColorCode
Imports SelectPdf

Namespace SelectPdf.Samples
    Partial Public Class GraphicElements
        Inherits Form

        Private Sub BtnCreatePdf_Click(sender As Object, e As EventArgs) _
            Handles BtnCreatePdf.Click
            Cursor = Cursors.WaitCursor
            Dim file As String = "Document.pdf"

            Try
                ' create a new pdf document
                Dim doc As New PdfDocument()

                ' add a new page to the document
                Dim page As PdfPage = doc.AddPage()

                ' define a rendering result object
                Dim result As PdfRenderingResult

                ' simple horizontal line element
                Dim line1 As New PdfLineElement(0, 0, 400, 0)
                line1.LineStyle.LineWidth = 3
                result = page.Add(line1)

                ' horizontal dotted red line element
                Dim line2 As New PdfLineElement(0, 30, 400, 30)
                line2.ForeColor = System.Drawing.Color.Red
                line2.LineStyle.LineWidth = 2
                line2.LineStyle.LineDashStyle = PdfLineDashStyle.Dot
                result = page.Add(line2)

                ' horizontal dashed blue line element with complex styles
                Dim line3 As New PdfLineElement(0, 60, 400, 60)
                line3.ForeColor = System.Drawing.Color.Blue
                line3.LineStyle.LineWidth = 2
                line3.LineStyle.LineDashStyle = PdfLineDashStyle.Dash
                line3.LineStyle.LineCapStyle = PdfLineCapStyle.RoundCap
                line3.LineStyle.LineJoinStyle = PdfLineJoinStyle.RoundJoin
                result = page.Add(line3)

                ' simple rectangle
                Dim rect1 As New PdfRectangleElement(0, 90, 400, 100)
                result = page.Add(rect1)

                ' simple circle
                Dim circ1 As New PdfCircleElement(50, 250, 50)
                circ1.ForeColor = System.Drawing.Color.Green
                result = page.Add(circ1)

                ' ellipse filled with gradient background color
                Dim elli1 As New PdfEllipseElement(300, 250, 100, 50)
                elli1.ForeColor = System.Drawing.Color.Brown
                elli1.Gradient = New PdfGradient(PdfGradientDirection.ForwardDiagonal, _
                                                 System.Drawing.Color.LightBlue, _
                                                 System.Drawing.Color.DarkBlue)
                elli1.LineStyle.LineWidth = 2
                result = page.Add(elli1)

                ' bezier curve
                Dim bez1 As New PdfBezierCurveElement(50, 350, 100, 400, 200, 350, _
                    250, 370)
                result = page.Add(bez1)

                ' save pdf document
                doc.Save(file)

                ' close pdf document
                doc.Close()
            Catch ex As Exception
                MessageBox.Show([String].Format("Error: {0}", ex.Message), "Error", _
                                MessageBoxButtons.OK, MessageBoxIcon.[Error])
                Return
            Finally
                Cursor = Cursors.Arrow
            End Try

            ' open generated pdf
            Try
                System.Diagnostics.Process.Start(file)
            Catch
                MessageBox.Show("Could not open generated pdf document", "Error", _
                                MessageBoxButtons.OK, MessageBoxIcon.[Error])
            End Try
        End Sub

        Public Sub New()
            InitializeComponent()
            Try
                ' display highlighted sample code
                Dim code As String = Helper.ReadSourceCode("GraphicElements.vb")
                WBSampleCode.DocumentText = New CodeColorizer().Colorize(code, Languages.VbDotNet)
            Catch
                WBSampleCode.DocumentText = "Sample code not available"
            End Try
        End Sub

    End Class
End Namespace
