Question:

I wanted to know that How to draw a cricle with coodrinates of the centre and Radius

by  |  earlier

0 LIKES UnLike

HI

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,

Form1

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()

Form2.ShowDialog()

End Sub

End Class

Form2

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)

Next

End Sub

End Class

Option Strict OnPublic 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) Next

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

 Tags:

   Report

2 ANSWERS


  1. Your problem is in the lines where you get a number from the text box. Like this-

    Dim radius As Double=form1.TextBox3

    A text box, returns a string. You have to evaluate the string to get a number from it.

    I think the VB function for this is called Eval().  Its a long time since I did any VB, so I'm not sure.


  2. UR error :

    The o/p val from the textbox is type string, which u capture in a double var.

    U must set the DataFormat property of the textbox to number.

    Check this for all 3 textbox.



Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions