Results 1 to 28 of 28

Thread: Drawing a circle with a center reference

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2010
    Posts
    264

    Re: Drawing a circle with a center reference

    Okay, thanks. Sorry to be a pest. I think it's just the syntax that's screwing me up. Sometimes I know what I want to do but I don't know how to write it. This being the first time using the Paint event isn't helping either. I'll give it another go though.

    Thanks for your patience.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2010
    Posts
    264

    Re: Drawing a circle with a center reference

    Finally, I got it!

    vb Code:
    1. Public Class Form1
    2.     Dim userClick As Boolean
    3.  
    4.     Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
    5.         userClick = True
    6.         Refresh()
    7.     End Sub
    8.  
    9.     Private Sub Form1_Paint1(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    10.         If userClick = True Then
    11.             Dim g As Graphics = e.Graphics
    12.             Dim pn As New Pen(Color.Blue, 3)
    13.             g.DrawEllipse(pn, 50, 50, 100, 100)
    14.         End If
    15.     End Sub
    16.  
    17. End Class

    Thanks for the help!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2010
    Posts
    264

    Re: Drawing a circle with a center reference

    Here's the rest. How can it be improved?

    vb Code:
    1. Public Class Form1
    2.     Dim userClick As Boolean
    3.  
    4.     Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
    5.         userClick = True
    6.         Me.Refresh()
    7.     End Sub
    8.  
    9.     Private Sub Form1_Paint1(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    10.  
    11.         If userClick = True Then
    12.             Dim g As Graphics = e.Graphics
    13.             Dim diameter As Int32 = 5
    14.             Dim random As New Random
    15.  
    16.             For count As Int32 = 1 To 50
    17.                 Dim radius As Int32 = CInt(diameter / 2)
    18.                 Dim xCenter As Int32 = CInt(Me.ClientSize.Width / 2) - radius
    19.                 Dim yCenter As Int32 = CInt(Me.ClientSize.Height / 2) - radius
    20.                 Dim penCurrent As New Pen(Color.FromArgb(random.Next(1, 256), random.Next(1, 256), random.Next(1, 256)), 4)
    21.  
    22.                 Me.CreateGraphics.DrawEllipse(penCurrent, xCenter, yCenter, diameter, diameter)
    23.                 diameter += 15
    24.  
    25.                 System.Threading.Thread.Sleep(45)
    26.             Next
    27.         End If
    28.     End Sub
    29.  
    30. End Class

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2010
    Posts
    264

    Re: Drawing a circle with a center reference

    Just noticed in my last post I forgot to replace CreateGraphics with g.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width