Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel

Public Class LinePlot
  Inherits PlotWindow

  Public Sub New()
    MyBase.New()
    LinePlot = Me
    InitializeComponent()
    bpen = New Pen(Color.Black)
  End Sub

  'Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal dispose As Boolean)
    MyBase.Dispose(dispose)
    components.Dispose()
  End Sub

#Region " Windows Form Designer generated code "

  'Required by the Windows Form Designer
  Private components As System.ComponentModel.Container
  Private WithEvents Pic As System.Windows.Forms.PictureBox

  Dim WithEvents LinePlot As System.Windows.Forms.Form

  '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.
  Private Sub InitializeComponent()
    Me.components = New System.ComponentModel.Container()
    Me.Pic = New System.Windows.Forms.PictureBox()

    '@design Me.TrayHeight = 0
    '@design Me.TrayLargeIcon = False
    '@design Me.TrayAutoArrange = True
    Pic.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    Pic.BackColor = System.Drawing.SystemColors.ActiveCaptionText
    Pic.Location = New System.Drawing.Point(24, 16)
    Pic.Size = New System.Drawing.Size(256, 216)
    Pic.TabIndex = 0
    Pic.TabStop = False
    Me.Text = "LinePlot"
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

    Me.Controls.Add(Pic)
  End Sub

#End Region

  Public Sub Pic_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Pic.Paint
    Dim g As Graphics = e.Graphics
    Dim i, ix, iy, ix1, iy1 As Integer
    Dim br As Brush
    Dim h As Integer
    h = Pic.Height
    If hasData Then
      For i = 1 To x.Length - 1
        ix = calcx(x(i - 1))
        iy = calcy(y(i - 1))
        ix1 = calcx(x(i))
        iy1 = calcy(y(i))
        g.DrawLine(bpen, ix, h - iy, ix1, h - iy1)
      Next
    End If
  End Sub

  Public Overrides Sub repaint()
    Pic.Refresh()
  End Sub

  Public Overloads Sub plot(ByVal x() As Single, ByVal y() As Single)
    MyBase.plot(x, y, Pic)
  End Sub
End Class
