﻿Imports GrapeCity.Spreadsheet
Imports GrapeCity.Spreadsheet.Drawing
Imports Spread.Common.Features.Spread.Common.Features.Sample

Public Class FlowChart
    Inherits BaseSampleControl
    Public Sub New()
        InitializeComponent()
        InitializeFlowchart()
    End Sub

    Private Sub InitializeFlowchart()
        FpSpread1.Features.EnhancedShapeEngine = True
        Dim blackARGB As GrapeCity.Core.SchemeThemeColors = GrapeCity.Core.SchemeThemeColors.Text1
        Dim workbook As IWorkbook = FpSpread1.AsWorkbook()
        Dim worksheet As IWorksheet = workbook.ActiveSheet
        Dim shapes As IShapes = FpSpread1.AsWorkbook().ActiveSheet.Shapes
        Dim title As IShape = shapes.AddTextEffect(PresetTextEffect.Unspecified, "HOW TO WRITE GOOD CODE:", "Comic Sans MS", 28, True, False, 112, 44)
        title.Fill.Visible = False
        title.Line.Visible = False
        title.Width = 610
        title.Height = 71
        title.TextFrame.CanEdit = True
        title.TextFrame.MarginBottom = 0
        title.TextFrame.MarginLeft = 0
        title.TextFrame.MarginRight = 0
        title.TextFrame.MarginTop = 0
        title.TextFrame.TextRange.Font.Fill.BackColor.ObjectThemeColor = blackARGB
        Dim start As IShape = shapes.AddShape(AutoShapeType.ProcessFlow, 190, 127, 192, 90)
        start.Fill.Visible = False
        start.Line.ForeColor.ObjectThemeColor = blackARGB
        start.Line.Weight = 3.0
        start.TextEffect.Alignment = TextEffectAlignment.Center
        start.TextEffect.FontName = "Comic Sans MS"
        start.TextEffect.FontSize = 20.0
        start.TextEffect.Text = "START" & vbLf & "PROJECT."
        start.TextFrame.CanEdit = True
        start.TextFrame.MarginBottom = 0
        start.TextFrame.MarginLeft = 0
        start.TextFrame.MarginRight = 0
        start.TextFrame.MarginTop = 0
        start.TextFrame.TextRange.Font.Fill.BackColor.ObjectThemeColor = blackARGB
        start.TextFrame.VerticalAnchor = VerticalAnchor.Middle
        start.TextFrame.WordWrap = True
        start.PickUp()
        Dim rightOrFast As IShape = shapes.AddShape(AutoShapeType.Diamond, 86, 278, 400, 280)
        rightOrFast.Apply()
        rightOrFast.TextEffect.Text = "DO" & vbLf & "THINGS" & vbLf & "RIGHT OR DO" & vbLf & "THEM FAST?"
        Dim arrow1 As IShape = shapes.AddConnector(ConnectorType.Straight, 0, 0, 100, 100)
        arrow1.Line.ForeColor.ObjectThemeColor = blackARGB
        arrow1.Line.Weight = 3.0
        arrow1.Line.EndArrowheadStyle = GrapeCity.Drawing.ArrowheadStyle.Arrow
        arrow1.ConnectorFormat.BeginConnect(start, 0)
        arrow1.ConnectorFormat.EndConnect(rightOrFast, 0)
        arrow1.RerouteConnections()
        Dim fast As IShape = shapes.AddTextEffect(PresetTextEffect.Unspecified, "FAST", "Comic Sans MS", 20, False, False, 488, 375)
        Dim codeFast As IShape = shapes.AddShape(AutoShapeType.ProcessFlow, 595, 373, 100, 90)
        codeFast.TextEffect.Text = "CODE" & vbLf & "FAST"
        Dim arrow2 As IShape = arrow1.Duplicate()
        arrow2.ConnectorFormat.BeginConnect(rightOrFast, 3)
        arrow2.ConnectorFormat.EndConnect(codeFast, 1)
        Dim doesItWorkYet As IShape = shapes.AddShape(AutoShapeType.Diamond, 495, 515, 300, 180)
        doesItWorkYet.TextEffect.Text = "DOES IT" & vbLf & "WORK" & vbLf & "YET?"
        Dim arrow3 As IShape = arrow1.Duplicate()
        arrow3.ConnectorFormat.BeginConnect(codeFast, 2)
        arrow3.ConnectorFormat.EndConnect(doesItWorkYet, 0)
        Dim No1 As IShape = shapes.AddTextEffect(PresetTextEffect.Unspecified, "NO", "Comic Sans MS", 20, False, False, 795, 565)
        Dim arrow4 As IShape = shapes.AddConnector(ConnectorType.Elbow, 0, 0, 100, 100)
        arrow4.Line.ForeColor.ObjectThemeColor = blackARGB
        arrow4.Line.Weight = 3.0
        arrow4.Line.EndArrowheadStyle = GrapeCity.Drawing.ArrowheadStyle.Arrow
        arrow4.ConnectorFormat.BeginConnect(doesItWorkYet, 3)
        arrow4.ConnectorFormat.EndConnect(codeFast, 3)
        arrow4.Adjustments(0) -= 0.75
        Dim right As IShape = shapes.AddTextEffect(PresetTextEffect.Unspecified, "RIGHT", "Comic Sans MS", 20, False, False, 290, 560)
        Dim codeWell As IShape = shapes.AddShape(AutoShapeType.ProcessFlow, 232, 628, 106, 90)
        codeWell.TextEffect.Text = "CODE" & vbLf & "WELL"
        Dim arrow5 As IShape = arrow1.Duplicate()
        arrow5.ConnectorFormat.BeginConnect(rightOrFast, 2)
        arrow5.ConnectorFormat.EndConnect(codeWell, 0)
        Dim areYouDoneYet As IShape = shapes.AddShape(AutoShapeType.Diamond, 105, 783, 360, 200)
        areYouDoneYet.TextEffect.Text = "ARE" & vbLf & "YOU DONE" & vbLf & "YET?"
        Dim arrow6 As IShape = shapes.AddConnector(ConnectorType.Straight, 0, 0, 100, 100)
        arrow6.ConnectorFormat.BeginConnect(codeWell, 2)
        arrow6.ConnectorFormat.EndConnect(areYouDoneYet, 0)
        Dim No2 As IShape = shapes.AddTextEffect(PresetTextEffect.Unspecified, "NO", "Comic Sans MS", 20, False, False, 465, 842)
        Dim arrow7 As IShape = arrow4.Duplicate()
        arrow7.ConnectorFormat.BeginConnect(areYouDoneYet, 3)
        arrow7.ConnectorFormat.EndConnect(codeWell, 3)
        arrow7.Adjustments(0) -= 0.75
        Dim No3 As IShape = shapes.AddTextEffect(PresetTextEffect.Unspecified, "NO, AND THE" & vbLf & "REQUIREMENTS" & vbLf & "HAVE CHANGED.", "Comic Sans MS", 20, False, False, 290, 990)
        Dim almostBut As IShape = shapes.AddTextEffect(PresetTextEffect.Unspecified, "ALMOST, BUT IT'S" & vbLf & "BECOME A MASS OF" & vbLf & "KLUDGES AND" & vbLf & "SPAGHETTI CODE.", "Comic Sans MS", 20, False, False, 655, 695)
        Dim throwItOut As IShape = shapes.AddShape(AutoShapeType.ProcessFlow, 125, 1150, 320, 90)
        throwItOut.TextEffect.Text = "THROW IT ALL OUT" & vbLf & "AND START OVER."
        Dim arrow8 As IShape = arrow1.Duplicate()
        arrow8.ConnectorFormat.BeginConnect(areYouDoneYet, 2)
        arrow8.ConnectorFormat.EndConnect(throwItOut, 0)
        Dim arrow9 As IShape = arrow4.Duplicate()
        arrow9.ConnectorFormat.BeginConnect(doesItWorkYet, 2)
        arrow9.ConnectorFormat.EndConnect(throwItOut, 3)
        Dim arrow10 As IShape = arrow9.Duplicate()
        arrow10.ConnectorFormat.BeginConnect(throwItOut, 1)
        arrow10.ConnectorFormat.EndConnect(rightOrFast, 1)
        Dim arrow11 As IShape = shapes.AddConnector(ConnectorType.Straight, 85, 1195, 125, 1195)
        arrow11.Line.ForeColor.ObjectThemeColor = blackARGB
        arrow11.Line.Weight = 3.0
        arrow11.Line.EndArrowheadStyle = GrapeCity.Drawing.ArrowheadStyle.Arrow
        arrow11.Flip(True)
        Dim cloud As IShape = shapes.AddShape(AutoShapeType.Cloud, 720, 950, 80, 80)
        cloud.TextEffect.Text = "?"
        Dim goodCode As IShape = shapes.AddShape(AutoShapeType.ProcessFlow, 710, 1070, 100, 100)
        goodCode.TextEffect.Text = "GOOD" & vbLf & "CODE"
        Dim arrow12 As IShape = arrow1.Duplicate()
        arrow12.ConnectorFormat.BeginConnect(cloud, 1)
        arrow12.ConnectorFormat.EndConnect(goodCode, 0)
        Dim range1 As IShapeRange = shapes.Range(New IShape() {codeFast, doesItWorkYet, codeWell, areYouDoneYet, throwItOut, cloud, goodCode})
        range1.Line.ForeColor.ObjectThemeColor = blackARGB
        range1.Line.Weight = 3.0
        range1.Fill.Visible = False
        range1.TextEffect.Alignment = TextEffectAlignment.Center
        range1.TextEffect.FontName = "Comic Sans MS"
        range1.TextEffect.FontSize = 20.0
        range1.TextFrame.CanEdit = True
        range1.TextFrame.MarginBottom = 0
        range1.TextFrame.MarginLeft = 0
        range1.TextFrame.MarginRight = 0
        range1.TextFrame.MarginTop = 0
        range1.TextFrame.TextRange.Font.Fill.BackColor.ObjectThemeColor = blackARGB
        range1.TextFrame.VerticalAnchor = VerticalAnchor.Middle
        range1.TextFrame.WordWrap = True
        Dim range2 As IShapeRange = shapes.Range(New IShape() {fast, No1, right, No2, No3, almostBut})
        range2.Fill.Visible = False
        range2.Line.Visible = False
        range2.TextFrame.CanEdit = True
        range2.TextFrame.MarginBottom = 0
        range2.TextFrame.MarginLeft = 0
        range2.TextFrame.MarginRight = 0
        range2.TextFrame.MarginTop = 0
        range2.TextFrame.TextRange.Font.Fill.BackColor.ObjectThemeColor = blackARGB

    End Sub
    Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, value As T) As T
        target = value
        Return value
    End Function
End Class

'
'FlowChart.Designer.vb
'

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class FlowChart

     'UserControl overrides dispose to clean up the component list.
     <System.Diagnostics.DebuggerNonUserCode()>
     Protected Shadows Sub Dispose(ByVal disposing As Boolean)
          Try
               If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
               End If
          Finally
               MyBase.Dispose(disposing)
          End Try
     End Sub

     'Required by the Windows Form Designer
     Private components As System.ComponentModel.IContainer

     'NOTE: The following procedure is required by the Windows Form Designer
     'It can be modified using the Windows Form Designer.  
     'Do not modify it using the code editor.
     <System.Diagnostics.DebuggerStepThrough()>
     Private Sub InitializeComponent()
          Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(FlowChart))
          Me.FpSpread1 = New FarPoint.Win.Spread.FpSpread(FarPoint.Win.Spread.LegacyBehaviors.None, CType(resources.GetObject("pnlMain.Controls"), Object))
          Me.FpSpread1_Sheet1 = Me.FpSpread1.GetSheet(0)
          Me.pnlMain.SuspendLayout()
          CType(Me.FpSpread1, System.ComponentModel.ISupportInitialize).BeginInit()
          Me.SuspendLayout()
          '
          'pnlMain
          '
          Me.pnlMain.Controls.Add(Me.FpSpread1)
          Me.pnlMain.Size = New System.Drawing.Size(600, 450)
          '
          'pnlControls
          '
          Me.pnlControls.Size = New System.Drawing.Size(199, 450)
          '
          'FpSpread1
          '
          Me.FpSpread1.Dock = System.Windows.Forms.DockStyle.Fill
          Me.FpSpread1.Font = New System.Drawing.Font("Calibri", 11.0!)
          Me.FpSpread1.Location = New System.Drawing.Point(0, 0)
          Me.FpSpread1.Name = "FpSpread1"
          Me.FpSpread1.Size = New System.Drawing.Size(600, 450)
          Me.FpSpread1.TabIndex = 0
          '
          'FlowChart
          '
          Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
          Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
          Me.Name = "Flow Chart"
          Me.Size = New System.Drawing.Size(800, 450)
          Me.pnlMain.ResumeLayout(False)
          CType(Me.FpSpread1, System.ComponentModel.ISupportInitialize).EndInit()
          Me.ResumeLayout(False)

     End Sub

     Friend WithEvents FpSpread1 As FarPoint.Win.Spread.FpSpread
     Friend WithEvents FpSpread1_Sheet1 As FarPoint.Win.Spread.SheetView
End Class
