1. Home
  2. Computing & Technology
  3. Visual Basic

GDI+ Graphics in Visual Basic 2005 .NET

The Conclusion of Peter's Program

By Dan Mabbutt, About.com

Aug 18 2007

Finally, the gadget that actually paints the Panel is:

Private Sub panMap_Paint( _
  ByVal sender As Object, _
  ByVal e As System.Windows.Forms.PaintEventArgs) _
  Handles panMap.Paint
Dim g As Graphics = e.Graphics
Dim I As Integer
Dim J As Integer
Dim K As Integer
Dim MyPen As Pen
Dim MyBrush As SolidBrush
For I = 0 To MaxRoom
  With MapArray(I)
    If .Visible Then
      If ShowLines Then
        MyPen = New Pen(Color.Blue, 2)
        For J = 0 To MaxWall
          K = Math.Abs(Room(I, J, Roo.RoomNr))

          If (K >= 0) AndAlso _
            (K <= MaxRoom) AndAlso _
            (Math.Abs(I - K) > 1) Then
            If MapArray(K).Visible Then
              g.DrawLine(MyPen, _
                  Convert.ToSingle( _
                  MapArray(K).CenterX + .CircleSize / 2), _
                  Convert.ToSingle( _
                  MapArray(K).CenterY + .CircleSize / 2), _
                  Convert.ToSingle( _
                  .CenterX + .CircleSize / 2), _
                  Convert.ToSingle( _
                  .CenterY + .CircleSize / 2))
            End If
          End If
        Next J
      End If
      If .Fill Then
        MyBrush = New SolidBrush(.PenColor)
        g.FillEllipse( _
        MyBrush, .CenterX, .CenterY, .CircleSize, .CircleSize)
      Else
        MyPen = New Pen(.PenColor, .PenWidth)
        g.DrawEllipse( _
        MyPen, .CenterX, .CenterY, .CircleSize, .CircleSize)
      End If
    End If
  End With
Next I
End Sub

Explore Visual Basic

More from About.com

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Using VB.NET
  5. GDI+ Graphics in Visual Basic 2005 .NET

©2008 About.com, a part of The New York Times Company.

All rights reserved.