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

Public Class BarPlot
  Inherits PlotWindow

  Private colors As ArrayList
  '-----    
  Public Sub New()
    MyBase.New()
    BarPlot = Me
    InitializeComponent()
    colors = New ArrayList()
    colors.Add(New SolidBrush(Color.Red))
    colors.Add(New SolidBrush(Color.Green))
    colors.Add(New SolidBrush(Color.Blue))
    colors.Add(New SolidBrush(Color.Magenta))
    colors.Add(New SolidBrush(Color.Yellow))
  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 BarPlot 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()

    Pic.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    Pic.BackColor = System.Drawing.SystemColors.ActiveCaptionText
    Pic.Location = New System.Drawing.Point(24, 24)
    Pic.Size = New System.Drawing.Size(256, 216)
    Pic.TabIndex = 0
    Pic.TabStop = False

    Me.Text = "BarPlot"
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

    Me.Controls.Add(Pic)
  End Sub

#End Region
  '-----    
  Public Overridable 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 As Integer
    Dim br As Brush
    If hasData Then
      For i = 0 To x.Length - 1
        ix = calcx(x(i))
        iy = calcy(y(i))
        br = CType(colors(i), Brush)
        g.FillRectangle(br, ix, h - iy, 20, iy)
      Next
    End If
  End Sub

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

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