19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

372 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

‘Set the initial center of the circle to the upper<br />

‘left corner of the form <strong>and</strong> set its radius to 500.<br />

m_x = 0<br />

m_y = 0<br />

m_r = 500<br />

End Sub<br />

Public Property Get Xcoord() As Integer<br />

Xcoord = m_x<br />

End Property<br />

Public Property Let Xcoord(ByVal vNewValue As Integer)<br />

m_x = vNewValue<br />

End Property<br />

Public Property Get Ycoord() As Integer<br />

Ycoord = m_y<br />

End Property<br />

Public Property Let Ycoord(ByVal vNewValue As Integer)<br />

m_y = vNewValue<br />

End Property<br />

Public Sub Show()<br />

‘Display the circle.<br />

‘See discussion of Circle method in Section 10.4.<br />

frmCircles.Circle (m_x, m_y), m_r<br />

End Sub<br />

Public Sub Move(Dist)<br />

‘Move the center of the circle Dist twips to the right<br />

‘<strong>and</strong> Dist twips down.<br />

m_x = m_x + Dist<br />

m_y = m_y + Dist<br />

RaiseEvent PositionChanged(m_x, m_y, m_r)<br />

Call Show<br />

End Sub<br />

‘Form code<br />

Private WithEvents round As CCircle<br />

Private Sub Form_Load()<br />

Set round = New CCircle<br />

End Sub<br />

Private Sub cmdMove_Click()<br />

round.Move (500)<br />

End Sub<br />

Private Sub round_PositionChanged(x As Integer, y As Integer, _<br />

r As Integer)<br />

‘This event is triggered when the center of the circle changes.<br />

‘The code determines if part of the circle is off the screen.<br />

If (x + r > frmCircles.Width) Or (y + r ]] frmCircles.Height) Then<br />

lblCaution.Caption = “Circle Off Screen”

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!