Hello all,

I'm looking for a way of "erasing" a randomly colored line in vb.net. I don't actually think that there is a way to destroy the line, rather, I'm looking for a way to change the line color to the same color as the background, effectively "erasing" it. Also, I'm looking for a way to randomly generate the line colors, then change them to the background of the form as previously stated. The code for that is commented out.

It's a pretty simple program in general. I have it randomly creating the lines (every 4 seconds) in a single color, just not randomly generating line color and changing them to the background color to be "erased"

The buttons just speeds/slows the model.

lines Code:
  1. Public Class Form1
  2.  
  3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.         Me.BackColor = Color.Aquamarine
  5.     End Sub
  6.  
  7.     Private Sub btnFaster_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFaster.Click
  8.         tmrTimer.Interval = tmrTimer.Interval - 10
  9.     End Sub
  10.  
  11.     Private Sub btnSlower_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSlower.Click
  12.         tmrTimer.Interval = tmrTimer.Interval + 10
  13.     End Sub
  14.  
  15.     Private Sub tmrTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrTimer.Tick
  16.         'Dim inicolor As New Random()
  17.         'Dim intR, intG, intB As Integer
  18.         'intR = inicolor.Next(0, 256) 'generates random rgb number
  19.         'intG = inicolor.Next(0, 256)
  20.         'intB = inicolor.Next(0, 256)
  21.         'Dim hexR, hexG, hexB As String
  22.         'hexR = intR.ToString("X").PadLeft(2, "0"c) 'converts it to hex
  23.         'hexG = intG.ToString("X").PadLeft(2, "0"c)
  24.         'hexB = intB.ToString("X").PadLeft(2, "0"c)
  25.         'Dim strColor As String
  26.         'strColor = "#" & hexR & hexG & hexB
  27.         'Dim var = Drawing.Color.FromArgb(intR, intG, intB)
  28.         'Me.BackColor = var
  29.         Dim formSurface As Graphics = Me.CreateGraphics 'creates surface
  30.         Dim line As Integer = (Int((5 - 1 + 1) * Rnd() + 1))
  31.         Dim pen As New Pen(Color.Green, line)
  32.         Dim p1horizontal As Integer = (Int((300 - 0 + 1) * Rnd() + 0)) 'generates 4 random line coordinates
  33.         Dim p1vertical As Integer = (Int((300 - 0 + 1) * Rnd() + 0))
  34.         Dim p2horizontal As Integer = (Int((300 - 0 + 1) * Rnd() + 0))
  35.         Dim p2vertical As Integer = (Int((300 - 0 + 1) * Rnd() + 0))
  36.         formSurface.DrawLine(pen, p1horizontal, p1vertical, p2horizontal, p2vertical)
  37.         Media.SystemSounds.Beep.Play()
  38.         formSurface.DrawLine(pen, p1horizontal, p1vertical, p2horizontal, p2vertical)
  39.  
  40.  
  41.     End Sub
  42. End Class

Thanks!