I am trying to draw a circle in VB.Net

Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint e.Graphics.DrawEllipse(Pens.AliceBlue, New Rectangle(New Point(0, 0), New Size(PictureBox1.Width, PictureBox1.Height))) End Sub 

I am trying to draw a circle in VB.Net, .Net version 4. Nothing is displayed in paintbox.

+4
source share
3 answers

Try using:

 e.Graphics.DrawEllipse(Pens.AliceBlue,e.ClipRectangle); 

It worked for me. You can also try:

 e.Graphics.DrawEllipse( Pens.AliceBlue, 0, 0, pictureBox1.Width-1, pictureBox1.Height-1); 

or

 Rectangle rect = e.ClipRectangle; rect.Inflate(-1, -1); e.Graphics.DrawEllipse(Pens.AliceBlue, rect); 
+5
source

Your code works for me, except that Color.AliceBlue almost identical to KnownColor.Control .

  rr gg bb Color.AliceBlue.ToArgb = F0 F8 FF KnownColor.Control.ToArgb = F0 F0 F0 Difference = 00 08 0F 

Try Pens.Navy :

 Private Sub PictureBox1_Paint(sender As System.Object, e As PaintEventArgs) Handles PictureBox1.Paint e.Graphics.DrawEllipse(Pens.Navy, New Rectangle(New Point(0, 0), PictureBox1.Size)) End Sub 
+1
source

http://msdn.microsoft.com/en-us/library/a3fd63x2(v=vs.80).aspx#Y1128

 ' Create pen. Dim blackPen As New Pen(Color.Black, 3) ' Create rectangle for ellipse. Dim rect As New Rectangle(0, 0, 200, 200) ' Draw ellipse to screen. e.Graphics.DrawEllipse(blackPen, rect) 
0
source

Source: https://habr.com/ru/post/1379437/


All Articles