Public Class frmCircle

  Dim WithEvents round As New Circle()

  Private Sub btnMove_Click(ByVal sender As System.Object,
                            ByVal e As System.EventArgs) Handles btnMove.Click
    round.Move(20)
    round.Show(picCircle.CreateGraphics)
  End Sub

  Private Sub btnQuit_Click(ByVal sender As System.Object,
                            ByVal e As System.EventArgs) Handles btnQuit.Click
    Me.Close()
  End Sub

  Sub round_PositionChanged(ByVal x As Integer,
    ByVal y As Integer, ByVal d As Integer) Handles round.PositionChanged
    'This event is triggered when the location of the circle changes.
    'The code determines if part of the circle is off the screen.
    If (x + d > picCircle.Width) Or
       (y + d > picCircle.Height) Then
      txtCaution.Text = "Circle Off Screen"
    End If
  End Sub
End Class     'frmCircle

Class Circle
  'Private m_x As Integer 'Dist from left side of picture box to circle
  'Private m_y As Integer 'Distance from top of picture box to circle
  'Private m_d As Integer 'Diameter of circle

  Public Event PositionChanged(ByVal x As Integer, ByVal y As Integer,
                               ByVal d As Integer)
    'Event is triggered when the circle moves

  Public Sub New()
    'Set the initial location of the circle to the upper-left
    'corner of the picture box, and set its diameter to 40.
    Xcoord = 0
    Ycoord = 0
    Diameter = 40
  End Sub

  Public Property Xcoord() As Integer
  '  Get
  '    Return m_x
  '  End Get
  '  Set(ByVal value As Integer)
  '    m_x = value
  '  End Set
  'End Property

  Public Property Ycoord() As Integer
  '  Get
  '    Return m_y
  '  End Get
  '  Set(ByVal value As Integer)
  '    m_y = value
  '  End Set
  'End Property

  Public Property Diameter() As Integer
  '  Get
  '    Return m_d
  '  End Get
  '  Set(ByVal value As Integer)
  '    m_d = Value
  '  End Set
  'End Property

  Sub Show(ByVal g As Graphics)
    'Draw a circle with the given graphics context
    g.DrawEllipse(Pens.Black, Xcoord, Ycoord, Diameter, Diameter)
  End Sub

  Sub Move(ByVal distance As Integer)
    Xcoord += distance
    Ycoord += distance
    RaiseEvent PositionChanged(Xcoord, Ycoord, Diameter)
  End Sub
End Class     'Circle
