Draw a Circle Vb.net

#1

  • New D.I.C Head

Reputation: 0

  • View blog
  • Posts: 10
  • Joined: 01-August 08

Draw circle

Post icon  Posted 03 Baronial 2008 - 09:06 AM

Hi
I am new to VB.net 2005
I wanted to know that How to depict a cricle with coodrinates of the center and Radius and at the same time i wanted to draw point(Having Cooridnates) in the same circle drawing.
Anyone pls help me ......

Is This A Good Question/Topic? 0

  • +

#2 gbertoli3 User is offline

Reputation: 41

  • View blog
  • Posts: 1,166
  • Joined: 23-June 08

Re: Draw circumvolve

Posted 03 August 2008 - x:27 AM

You should utilize the Organisation.Cartoon.Graphics

              Dim grand As Organisation.Drawing.Graphics 		Dim textBox1 As New TextBox() 		g = textBox1.CreateGraphics() 		m.DrawEllipse(Pens.Black, 0, 0, 100, 100)            

From now on provide attempt or no i will assist you.

#3 Martyr2 User is offline

Reputation: 5623

  • View blog
  • Posts: xiv,706
  • Joined: 18-April 07

Re: Depict circumvolve

Posted 03 Baronial 2008 - 10:28 AM

It is site policy that we inquire a person to provide a "all-time endeavor" approach to a solution earlier we can help them. This means we like to meet what code yous accept written to endeavour and solve the problem. We can and so unremarkably assist.

However I am going to fudge on that rule a footling and give you lot a neat showtime in accomplishing this job...

              Private Sub DrawACircle(ByRef g As Graphics, ByRef center As Point, ByVal radius As Integer)         ' Select a pen object and get in ruby-red         Dim pn Every bit New Pen(Color.Red)          ' Create a bounding rectangle and make its center the eye of our signal         ' Then make its width two * the radius         ' Then draw our ellipse         Dim rect Every bit New Rectangle(center.X / 2, center.Y / two, radius * 2, radius * 2)         1000.DrawEllipse(pn, rect)     Finish Sub            

Here I have given y'all a basic drawing circumvolve office. It takes a graphics object (which I will explicate in a second) a bespeak structure and an integer representing the radius (you lot could brand this a double if you like, just brand sure you lot change the advisable code lines).

What you tin practise with this is telephone call it from the Paint outcome of your class. Ane of the parameters to this issue is a PaintEventArgs object which you lot can use to get a graphics object. A graphics object can exist thought of every bit a "canvas" to draw on. If you want to depict on the course, yous get the class's sail. We can laissez passer around this sheet to functions and each function can draw on it. Here we accept it beingness passed to our office for drawing a circle.

Then how do we get information technology to draw two circles? We call the office twice from the paint event. Or we can create other functions that draw and call them all from the paint result in order. Whenever the form needs to be painted, it volition execute all the functions for redrawing.

Our call to the function volition look like this in our paint event...

DrawCircle(e.Graphics, new Bespeak(100,100), 50)            

Here we are going to describe a reddish circumvolve with a centre point of 100 100 and a radius of 50.

Get more than information by searching the keyword "GDI in VB.NET" for more information.

Savour!

"At DIC we exist ellipse drawing code ninjas... ok who stole my last five ellipses? I drew them in crayon and it was a lot of piece of work. Bastards!" :snap:

#iv gbertoli3 User is offline

Reputation: 41

  • View blog
  • Posts: 1,166
  • Joined: 23-June 08

Re: Draw circle

Posted 03 Baronial 2008 - 10:31 AM

View PostMartyr2, on three Aug, 2008 - x:28 AM, said:

It is site policy that nosotros ask a person to provide a "best effort" approach to a solution before we can help them. This means we similar to see what lawmaking you lot take written to endeavor and solve the problem. We tin can then normally assistance.

Withal I am going to fudge on that rule a piffling and give you a great offset in accomplishing this chore...

                Private Sub DrawACircle(ByRef g Every bit Graphics, ByRef center Every bit Point, ByVal radius As Integer)         ' Select a pen object and go far red         Dim pn Every bit New Pen(Color.Red)          ' Create a bounding rectangle and brand its center the center of our bespeak         ' Then make its width 2 * the radius         ' Then draw our ellipse         Dim rect As New Rectangle(center.X / two, center.Y / 2, radius * 2, radius * 2)         thou.DrawEllipse(pn, rect)     End Sub              

Hither I have given yous a basic drawing circle function. It takes a graphics object (which I volition explicate in a second) a point structure and an integer representing the radius (you could brand this a double if you similar, just brand sure yous modify the appropriate code lines).

What you tin do with this is call it from the Paint event of your grade. 1 of the parameters to this outcome is a PaintEventArgs object which yous can use to get a graphics object. A graphics object can exist idea of every bit a "canvas" to draw on. If y'all want to depict on the form, you get the form'due south canvas. We can pass around this canvas to functions and each function can draw on it. Hither nosotros accept it being passed to our function for drawing a circle.

So how practice we get information technology to depict two circles? We call the role twice from the paint consequence. Or we tin can create other functions that draw and call them all from the paint event in club. Whenever the grade needs to be painted, information technology will execute all the functions for redrawing.

Our telephone call to the function will look like this in our paint consequence...

DrawCircle(eastward.Graphics, new Betoken(100,100), l)              

Here we are going to draw a red circle with a eye signal of 100 100 and a radius of 50.

Get more information past searching the keyword "GDI in VB.NET" for more information.

Enjoy!

"At DIC we exist ellipse drawing code ninjas... ok who stole my last 5 ellipses? I drew them in crayon and it was a lot of work. Bastards!" :snap:

Thats a little better than what I wrote, just I was simply trying to be fast.

#5 Martyr2 User is offline

Reputation: 5623

  • View blog
  • Posts: 14,706
  • Joined: 18-April 07

Re: Describe circle

Posted 03 August 2008 - 10:34 AM

No problem as long as y'all are accurate. I broke the rules a petty and so shhhh don't tell anyone. :)

#6 gbertoli3 User is offline

Reputation: 41

  • View blog
  • Posts: i,166
  • Joined: 23-June 08

Re: Depict circle

Posted 03 August 2008 - 11:08 AM

View PostMartyr2, on 3 Aug, 2008 - 10:34 AM, said:

No problem as long equally you are accurate. I bankrupt the rules a little so shhhh don't tell anyone. :)

Don't worry I can go on a secret.

Mums the discussion

#7 surveyor User is offline

  • New D.I.C Head

Reputation: 0

  • View blog
  • Posts: ten
  • Joined: 01-August 08

Re: Describe circle

Posted 03 Baronial 2008 - 02:08 PM

HI
I have created 2 forms
In form1 ,at that place are 3 textboxes,for x,y coordinates and radius and one button besides
if i enter the 10,y,r values in the form1 and i wanted to encounter the circle in form 2 in the centre,
anyone tin pls help me,

Form1

Public Class Form1     Dim x Every bit Double     Dim y As Double     Dim r Equally Double      Private Sub Button1_Click(ByVal sender Every bit System.Object, ByVal e As Arrangement.EventArgs) Handles Button1.Click         Dim Form2 Every bit New Form2()         Form2.ShowDialog()     End Sub End Class            

Form two

Option Strict On Public Class Form2     Private Sub form1_paint(ByVal sender Equally Object, ByVal e As Arrangement.Windows.Forms.PaintEventArgs) Handles Me.Paint         Dim form1 As New Form1()         Me.BackColor = Color.Black         Dim centreX Equally Double = form1.TextBox1         Dim centreY As Double = form1.TextBox2         Dim apen As New Pen(Colour.White, one)         Dim radius As Double = form1.TextBox3         Const Pi As Double = Math.PI         Dim x1, y1 As Integer         For num As Double = 0 To ii * Pi Footstep 0.01             x1 = Convert.ToInt32(radius * Math.Cos(num) + centreX)             y1 = Catechumen.ToInt32(radius * Math.Sin(num) + centreY)             e.Graphics.DrawLine(apen, x1, y1, x1 + ane, y1)         Side by side     End Sub End Course            

This mail service has been edited by gabehabe: 03 Baronial 2008 - 02:xx PM

#8 gabehabe User is offline

Reputation: 1440

  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Draw circle

Posted 03 Baronial 2008 - 02:nineteen PM

Delight don't double post. Threads merged.

Oh, and :code:

#9 MarkH007 User is offline

  • New D.I.C Head

Reputation: 0

  • View blog
  • Posts: three
  • Joined: xx-Apr 12

Re: Draw circle

Posted 28 May 2019 - 07:52 AM

View Postgbertoli3, on 03 August 2008 - 10:27 AM, said:

You should use the Arrangement.Drawing.Graphics

                Dim g As Organization.Drawing.Graphics 		Dim textBox1 Every bit New TextBox() 		g = textBox1.CreateGraphics() 		g.DrawEllipse(Pens.Blackness, 0, 0, 100, 100)              

From now on provide endeavor or no i volition help you lot.

Not to violate rules, but, this piffling snippet is exactly what i was looking for ;)

hollowayhenter1962.blogspot.com

Source: https://www.dreamincode.net/forums/topic/59525-draw-circle/

0 Response to "Draw a Circle Vb.net"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel