I am having some trouble drawing a circle that is constant when the program runs. right now I am able to create one of my clock hands (that is going counterclockwise), but I can't figure out how to draw the circle of the clock..any suggestions?

Option Strict On
Imports System.Math
Public Class Form1
    Dim arr(359) As PointF, counter As Integer

    Function rads(ByVal deg As Double) As Double
        Return deg * PI / 180
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, _
                ByVal e As System.EventArgs) Handles MyBase.Load

        For i As Integer = 0 To 359
            arr(i).X = 100 * Convert.ToSingle(Cos(rads(i))) + 125
            arr(i).Y = -100 * Convert.ToSingle(Sin(rads(i))) + 125
        Next
    End Sub

    Private Sub TestButton_Click(ByVal sender As System.Object, _
                ByVal e As System.EventArgs) Handles TestButton.Click

        Timer1.Enabled = True

    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, _
                ByVal e As System.EventArgs) Handles Timer1.Tick

        Dim gr As Graphics = picOut.CreateGraphics
        Dim a As Graphics = picOut.CreateGraphics

        Dim pn As New Pen(Color.Red)
        Dim rect As New Rectangle(0, 0, arr(i).X * 2, arr(i).Y * 2)
        g.DrawEllipse(pn, rect)


        counter += 1 : If counter = 360 Then counter = 0
        gr.Clear(Color.Red)
        gr.DrawLine(Pens.Black, 125, 125, arr(counter).X, arr(counter).Y)



    End Sub
End Class

I tried to follow that example to the letter, but it still doesn't make anything come out on the screen aside from my ticking hand. I also tried to follow some other people's advice by using me.cirle, which apparently doesn't exist in VB. Any other ideas?

The problem might be with the arr(i) values. Have you tried checking what those values (X & Y) returns?

Edited 6 Years Ago by farooqaaa: n/a

Hi,

Here's how I did it to draw a circle with a timer.

Public Class Form1
    Dim count As Integer = 0 ' start count of counter

    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
    Private Sub TestButton_Click(ByVal sender As System.Object, _
                                 ByVal e As System.EventArgs) Handles Testbutton.Click
        Timer1.Enabled = True
    End Sub
    Private Sub Timer1_Tick(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles Timer1.Tick
        count += 1
        Dim x As Integer
        x = -90 + count
        Dim mypen As New Pen(Color.Black, 3)
        picOut.CreateGraphics.DrawArc(mypen, 50, 50, 125, 125, x, CInt(count))
        picOut.CreateGraphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        If count = 180 Then
            count = 0  ' to reset the counter
            picOut.Refresh() ' to reset the picturebox
        End If
    End Sub

' In the paint event of the picturebox piant an Ellipse with a Red color.
        Private Sub picOut_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picOut.Paint
        Dim mypen As New Pen(Color.Red, 3)
        e.Graphics.DrawEllipse(mypen, 50, 50, 125, 125)
        e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
    End Sub
End Class
This article has been dead for over six months. Start a new discussion instead.