I wanted to know that How to draw a cricle with coodrinates of the centre and Radius in VB.Net 2005

vb.net Egypt
  • 12 years ago

    I have created 2 forms
    In form1 ,there are 3 textboxes,for x,y coordinates and radius and one button also
    if i enter the x,y,r values in the form1 and i wanted to see the circle in form 2 in the centre,
    anyone can pls help me,

    Public Class Form1
    Dim x As Double
    Dim y As Double
    Dim r As Double

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim Form2 As New Form2()
    End Sub
    End Class
    Option Strict On
    Public Class Form2
    Private Sub form1_paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    Dim form1 As New Form1()
    Me.BackColor = Color.Black
    Dim centreX As Double = form1.TextBox1
    Dim centreY As Double = form1.TextBox2
    Dim apen As New Pen(Color.White, 1)
    Dim radius As Double = form1.TextBox3
    Const Pi As Double = Math.PI
    Dim x1, y1 As Integer
    For num As Double = 0 To 2 * Pi Step 0.01
    x1 = Convert.ToInt32(radius * Math.Cos(num) centreX)
    y1 = Convert.ToInt32(radius * Math.Sin(num) centreY)
    e.Graphics.DrawLine(apen, x1, y1, x1 1, y1)
    End Sub
    End Class

     and Now i found some error messageslike
    option strict on disallows implicts conversation from string to double

    so pls help out


  • 12 years ago

    You made many mistakes (e.g. chaotic what does Forms1 event in Form2? ...etc).
    Basically also, you didn't noticed that since qbasic there is Circle function for circles? Smiley Face
    Only joke. There is no circle in Visual Basic, since vb.net or so. You may use DrawEllipse insted, which is
    the same... or fillEllipse. doesn't matter. Here is example of circle for you - nearly what you tried.
    It is in VB 2008 (Go and get it, it is also free, and in 2005 there are bugs Wink)

  • 12 years ago

    Just to add to this, the 'option strict on disallows implicts conversation from string to double' will occur in the places where you are converting strings to doubles.  Examples of where this happens is below.

    Dim centreX As Double = form1.TextBox1
    Dim centreY As Double = form1.TextBox2
    Dim radius As Double = form1.TextBox3

    You can use the CDbl function to convert the strings to doubles which will remove the error messages. 

    Dim centreX As Double = CDbl(form1.TextBox1)
    Dim centreY As Double = CDbl(form1.TextBox2)
    Dim radius As Double = CDbl(form1.TextBox3)


Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are 10 types of people in the world, those who can read binary, and those who can't.”