VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Circle Drawing Example

by G-Man (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

This code is simply to illustrate the mathematical operations necessary to draw a circle. Of course I realize VB has built in functions for this, but thought this might be useful for some to understand. In my example, I use a picture box with the PSet method to do the drawing.

Assumes
Simply create a form with a decent size picture box (picture1), a text box we will enter the radius in (text1), a command button to draw the circle (command1), and a command button for exit (command2). Paste the code I have supplied and run it.

Rate Circle Drawing Example

Private Sub Command1_Click()
  Dim intRadius, intDegree As Integer
  Dim sngX, sngY As Single
  
  If IsNumeric(Text1.Text) Then
    intRadius = Text1.Text
    For intDegree = 1 To 360
      sngX = (Cos(intDegree) * intRadius) + intRadius
      sngY = intRadius - (Sin(intDegree) * intRadius)
      Picture1.PSet (sngX, sngY), vbBlack
    Next
  Else
    MsgBox "Please enter a numeric value for the radius."
    Text1.SetFocus
  End If
End Sub
Private Sub Command2_Click()
  Unload Form1
End Sub

Download this snippet    Add to My Saved Code

Circle Drawing Example Comments

No comments have been posted about Circle Drawing Example. Why not be the first to post a comment about Circle Drawing Example.

Post your comment

Subject:
Message:
0/1000 characters