Visual Studio 2005: VB fill circle automatic

  • Thread starter Thread starter Slickuser
  • Start date Start date
S

Slickuser

How do I automatic move the X & Y to create a ellipse function as
below, DrawCircle?

Or there any sample source code out there?

I want it move down by user input. How can I achieve this? Thanks.

Imports System
Imports System.Drawing

Public Class circle

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

End Sub

Private Sub mainTab_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim myPen As New
System.Drawing.Pen(System.Drawing.Color.Black)
myPen.DashStyle = Drawing.Drawing2D.DashStyle.Solid

Dim widthPen As Integer = 10
myPen.Width = widthPen

Dim x1 As Integer = 10
Dim y1 As Integer = 20
Dim y2 As Integer = 70
e.Graphics.DrawLine(myPen, x1, y1, x1, y2)

x1 = x1 + 25 + widthPen
e.Graphics.DrawLine(myPen, x1, y1, x1, y2)

myPen.Dispose()
End Sub

Private Sub DrawCircle(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint

' Create pen.
Dim redBrush As New SolidBrush(Color.Red)

' Create location and size of ellipse.
Dim x As Integer = 75
Dim y As Integer = 25
Dim width As Integer = 75
Dim height As Integer = 50

' Draw ellipse to screen.
e.Graphics.FillEllipse(redBrush, x, y, width, height)

End Sub

End Class
 
Now I got it work, now I want to remove the the ellipse at certain X &
Y.

I also have another program is that when I minimize it, my previous
ellipse is not visible. How can I fix this and remove the the ellipse
object at certain X & y? Thanks.

Here is the code:


Imports System
Imports System.Drawing


Public Class circle

Friend graphicGlobal As System.Drawing.Graphics
Dim x_global As Integer = 10
Dim y_global As Integer = 10
Dim width_global As Integer = 20
Dim height_global As Integer = 20

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

End Sub

Private Sub mainTab_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim myPen As New
System.Drawing.Pen(System.Drawing.Color.Black)
myPen.DashStyle = Drawing.Drawing2D.DashStyle.Solid

Dim widthPen As Integer = 10
myPen.Width = widthPen

Dim x1 As Integer = 10
Dim y1 As Integer = 20
Dim y2 As Integer = 70
e.Graphics.DrawLine(myPen, x1, y1, x1, y2)

x1 = x1 + 25 + widthPen
e.Graphics.DrawLine(myPen, x1, y1, x1, y2)

myPen.Dispose()
End Sub



Private Sub DrawCircle(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint

' Create brush
Dim redBrush As New SolidBrush(Color.Red)

' Create location and size of ellipse.
Dim x As Integer = 75
Dim y As Integer = 25
Dim width As Integer = 75
Dim height As Integer = 50

' Draw ellipse to screen.
e.Graphics.FillEllipse(redBrush, x, y, width, height)

Dim blueBrush As New SolidBrush(Color.Blue)
Dim greenBrush As New SolidBrush(Color.Green)

DrawNote(40, 200, 50, 50, blueBrush)
DrawNote(60, 130, 50, 50, greenBrush)

End Sub

'good
'Private Sub DrawNote(ByVal x As Integer, ByVal y As Integer,
ByVal width As Integer, ByVal height As Integer, ByVal colorBrush As
SolidBrush, ByVal e As System.Windows.Forms.PaintEventArgs)

'Dim redBrush As New SolidBrush(Color.Red)
'e.Graphics.FillEllipse(colorBrush, x, y, width, height)

'End Sub


Private Sub DrawNote(ByVal x As Integer, ByVal y As Integer, ByVal
width As Integer, ByVal height As Integer, ByVal colorBrush As
SolidBrush)

graphicGlobal = CreateGraphics()

graphicGlobal.FillEllipse(colorBrush, x, y, width, height)

End Sub


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

Dim colorBrush As New SolidBrush(Color.Magenta)
Dim colorBrush2 As New SolidBrush(Color.Cyan)

DrawNote(x_global, y_global, 20, 20, colorBrush)

DrawNote(x_global + 15, y_global + 15, 20, 20, colorBrush2)

x_global = x_global + 30
y_global = y_global + 30

End Sub

End Class
 
Slickuser said:
Now I got it work, now I want to remove the the ellipse at certain X &
Y.

I also have another program is that when I minimize it, my previous
ellipse is not visible. How can I fix this and remove the the ellipse
object at certain X & y? Thanks.

Here is the code:


Imports System
Imports System.Drawing


Public Class circle

Friend graphicGlobal As System.Drawing.Graphics
Dim x_global As Integer = 10
Dim y_global As Integer = 10
Dim width_global As Integer = 20
Dim height_global As Integer = 20

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

End Sub

Private Sub mainTab_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim myPen As New
System.Drawing.Pen(System.Drawing.Color.Black)
myPen.DashStyle = Drawing.Drawing2D.DashStyle.Solid

Dim widthPen As Integer = 10
myPen.Width = widthPen

Dim x1 As Integer = 10
Dim y1 As Integer = 20
Dim y2 As Integer = 70
e.Graphics.DrawLine(myPen, x1, y1, x1, y2)

x1 = x1 + 25 + widthPen
e.Graphics.DrawLine(myPen, x1, y1, x1, y2)

myPen.Dispose()
End Sub



Private Sub DrawCircle(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint

' Create brush
Dim redBrush As New SolidBrush(Color.Red)

' Create location and size of ellipse.
Dim x As Integer = 75
Dim y As Integer = 25
Dim width As Integer = 75
Dim height As Integer = 50

' Draw ellipse to screen.
e.Graphics.FillEllipse(redBrush, x, y, width, height)

Dim blueBrush As New SolidBrush(Color.Blue)
Dim greenBrush As New SolidBrush(Color.Green)

DrawNote(40, 200, 50, 50, blueBrush)
DrawNote(60, 130, 50, 50, greenBrush)

End Sub

'good
'Private Sub DrawNote(ByVal x As Integer, ByVal y As Integer,
ByVal width As Integer, ByVal height As Integer, ByVal colorBrush As
SolidBrush, ByVal e As System.Windows.Forms.PaintEventArgs)

'Dim redBrush As New SolidBrush(Color.Red)
'e.Graphics.FillEllipse(colorBrush, x, y, width, height)

'End Sub


Private Sub DrawNote(ByVal x As Integer, ByVal y As Integer, ByVal
width As Integer, ByVal height As Integer, ByVal colorBrush As
SolidBrush)

graphicGlobal = CreateGraphics()

graphicGlobal.FillEllipse(colorBrush, x, y, width, height)

End Sub


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

Dim colorBrush As New SolidBrush(Color.Magenta)
Dim colorBrush2 As New SolidBrush(Color.Cyan)

DrawNote(x_global, y_global, 20, 20, colorBrush)

DrawNote(x_global + 15, y_global + 15, 20, 20, colorBrush2)

x_global = x_global + 30
y_global = y_global + 30

End Sub

End Class

If I understand what you are trying to do, you want to have control on the
drawing of an elipse as the control is repainted. You don't "erase" or
"remove" what is already there, but rather repaint the control. Think about
what you want drawn in your control and code your mainTab_Paint routine to
that.
 
Yes, is corrected. I want to control the ellipse that was previous
drawn.

If I re-draw with a different color (same as background) then it will
overlap and hide it.

But the problem is I don't know where that previous X & Y are (since
my X & Y will be random, my example here is increment every 10s by 30
though).
 
Yes, is corrected. I want to control the ellipse that was previous
If I re-draw with a different color (same as background) then it will
overlap and hide it.

But the problem is I don't know where that previous X & Y are (since
my X & Y will be random, my example here is increment every 10s by 30
though).
On Nov 27, 4:52 am, Family Tree Mike


You can do a graphics clear at the top of your mainTab_Paint(), but there
may be some flickering if the updates are very frequent.
 
Back
Top