Private Sub picHisto_Paint(ByVal sender As Object, ByVal e _
As System.Windows.Forms.PaintEventArgs) Handles _
picHisto.Paint
e.Graphics.Clear(picHisto.BackColor)
' Flip vertically and scale to fit.
Dim scalex As Single = picHisto.Width / _
(m_DataValues.GetUpperBound(0) + 2)
Dim scaley As Single = -picHisto.Height / (MAX_VALUE + _
10)
e.Graphics.ScaleTransform( _
scalex, scaley, MatrixOrder.Append)
' Translate so (0, MAX_VALUE + 10) maps to the origin.
e.Graphics.TranslateTransform(0, picHisto.Height, _
MatrixOrder.Append)
' Draw the histogram.
For i As Integer = 0 To m_DataValues.GetUpperBound(0)
Dim rect As New Rectangle(i, 0, 1, m_DataValues(i))
Dim brush_color As Color = _
Color.FromArgb(&HC0FFFFFF And _
m_Colors(i).ToArgb())
Dim the_brush As New SolidBrush(brush_color)
Dim pen_color As Color = Color.FromArgb(&HC0, _
m_Colors(i).R / 2, m_Colors(i).G / 2, _
m_Colors(i).B / 2)
'Dim the_pen As New Pen(pen_color, 0)
Dim the_pen As New Pen(Color.Black, 0)
' Draw hidden lines.
e.Graphics.DrawLine(the_pen, CSng(i + 0.5), 0 + 10, _
CSng(i + 0.5), m_DataValues(i) + 10)
e.Graphics.DrawLine(the_pen, CSng(i + 0.5), 0 + 10, _
CSng(i + 1.5), 0 + 10)
' Face.
Dim pts() As PointF
pts = New PointF() { _
New PointF(i, 0), _
New PointF(i + 1, 0), _
New PointF(i + 1, m_DataValues(i)), _
New PointF(i, m_DataValues(i)) _
}
e.Graphics.FillPolygon(the_brush, pts)
e.Graphics.DrawPolygon(the_pen, pts)
' Top.
pts = New PointF() { _
New PointF(i, m_DataValues(i)), _
New PointF(i + 0.5, m_DataValues(i) + 10), _
New PointF(i + 1.5, m_DataValues(i) + 10), _
New PointF(i + 1, m_DataValues(i)) _
}
e.Graphics.FillPolygon(the_brush, pts)
e.Graphics.DrawPolygon(the_pen, pts)
' Side.
pts = New PointF() { _
New PointF(i + 1, 0), _
New PointF(i + 1, m_DataValues(i)), _
New PointF(i + 1.5, m_DataValues(i) + 10), _
New PointF(i + 1.5, 10) _
}
e.Graphics.FillPolygon(the_brush, pts)
e.Graphics.DrawPolygon(the_pen, pts)
e.Graphics.DrawRectangle(the_pen, rect)
the_brush.Dispose()
the_pen.Dispose()
Next i
e.Graphics.ResetTransform()
e.Graphics.DrawRectangle(Pens.Black, 0, 0, _
picHisto.Width - 1, picHisto.Height - 1)
End Sub
|