Answered by:
help me in vb?

Question
-
I've to draw line on form, once i click the start button, I've timer and RandomGenerator that Generate the #'s and those #'s I've to use for my X and Y Coordinate to draw a line, I've code for draw line, but I've to draw a line each 3 second and the previous line has to clear by it self so I dont know how to clear the previous line. My code keep giving me a line... so please help me thanks
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Draw() Dim g As Graphics = Me.CreateGraphics Dim myRandomGenerator As System.Random Dim X1, X2 As Integer Dim Y1, Y2 As Integer myRandomGenerator = New System.Random X1 = myRandomGenerator.Next(1, 300) 'generator for picbox1 and dice 1 Y1 = myRandomGenerator.Next(1, 300) ' generator for picbox2 and dice 2 X2 = myRandomGenerator.Next(1, 50) Y2 = myRandomGenerator.Next(1, 50) g.DrawLine(Pens.Blue, X1, Y1, X2, Y2) End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Timer1.Interval = 1200 Call Draw() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Start() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Timer1.Stop() End Sub End Class
Monday, May 18, 2009 4:40 PM
Answers
-
Private Sub Draw() Dim g As Graphics = Me.CreateGraphics Dim myRandomGenerator As System.Random Dim X1, X2 As Integer Dim Y1, Y2 As Integer g.Clear(Me.BackColor)'this will clear the previous line myRandomGenerator = New System.Random X1 = myRandomGenerator.Next(1, 300) 'generator for picbox1 and dice 1 Y1 = myRandomGenerator.Next(1, 300) ' generator for picbox2 and dice 2 X2 = myRandomGenerator.Next(1, 50) Y2 = myRandomGenerator.Next(1, 50) g.DrawLine(Pens.Blue, X1, Y1, X2, Y2) End Sub
kaymaf
I hope this helps, if that is what you want, just mark it as answer so that we can move on- Marked as answer by Xingwei Hu Monday, May 25, 2009 6:22 AM
Monday, May 18, 2009 5:21 PM
All replies
-
use
g.clear(me.backcolor) 'toclear the line
kaymaf
I hope this helps, if that is what you want, just mark it as answer so that we can move onMonday, May 18, 2009 5:11 PM -
Private Sub Draw() Dim g As Graphics = Me.CreateGraphics Dim myRandomGenerator As System.Random Dim X1, X2 As Integer Dim Y1, Y2 As Integer g.Clear(Me.BackColor)'this will clear the previous line myRandomGenerator = New System.Random X1 = myRandomGenerator.Next(1, 300) 'generator for picbox1 and dice 1 Y1 = myRandomGenerator.Next(1, 300) ' generator for picbox2 and dice 2 X2 = myRandomGenerator.Next(1, 50) Y2 = myRandomGenerator.Next(1, 50) g.DrawLine(Pens.Blue, X1, Y1, X2, Y2) End Sub
kaymaf
I hope this helps, if that is what you want, just mark it as answer so that we can move on- Marked as answer by Xingwei Hu Monday, May 25, 2009 6:22 AM
Monday, May 18, 2009 5:21 PM