Question[Help]Random Color Background[Solved]

Posts 115 of 20 · Page 1 of 2
[Help]Random Color Background[Solved]
Ok guys i have a timer set to 1000 intervals. and i want my background of form1 to change every 5 mili sec.

here is my code so far. how do i have it change to next color by itself after 5 mili secs

[php]Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Timer1.Enabled = True

Me.BackColor = Color.DarkBlue

Me.BackColor = Color.Black

End Sub
End Class[/php]



Or what about this. How would i finish

[php]Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Color = Me.BackColor

Select Case Color

Me.BackColor = Color.DarkBlue

Me.BackColor = Color.Black

End Select

End Sub
End Class[/php]
After some googling I found that it would work if you did:

Code:
        Me.BackColor = Color.Black
        Me.Refresh()
        System.Threading.Thread.Sleep(50)
        Me.Refresh()
        System.Threading.Thread.Sleep(50)
        Me.BackColor = Color.DarkBlue
        Me.Refresh()
        System.Threading.Thread.Sleep(50)
        Me.BackColor = Color.'Insert Color here
Does for me. I think it just passes too quickly to see well enough. Better at 10 milliseconds or a delay of 100 instead of 50.
Waiting for nextgen*
copy and paste in your exact code from vb.

nig ga same here. you code?
Quote Originally Posted by zmansquared View Post
copy and paste in your exact code from vb.

nig ga same here. you code?
No, I google


Set timer to change at a specific interval

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

Dim i As Integer
i = Rnd() * 3 + 1

Select Case i

Case 1
Me.BackColor = Color.Black
Case 2
Me.BackColor = Color.DarkBlue
Case 3

'yada yada
End Select

End Sub
[/php]



Always set I = to rnd * the number of cases you will have
haha, that works too.

have you guys picked a new Ca min?

i really want to join the new fag agency
I have:

Code:
Public Class Form1
    Private Sub btnStartDiscoShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartDiscoShow.Click
        Me.BackColor = Color.Black
        Me.Refresh()
        System.Threading.Thread.Sleep(50)
        Me.Refresh()
        System.Threading.Thread.Sleep(50)
        Me.BackColor = Color.Red
        Me.Refresh()
        System.Threading.Thread.Sleep(50)
        Me.BackColor = Color.Yellow
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.BackColor = Color.Black
    End Sub
End Class
I'm using black, red, and yellow so I can see them better. Darkblue and black you may not see the change.

And thanks Nextgen.

EDIT: Just tested yours out Nextgen and it works quite well. Thanks!
Quote Originally Posted by Shark23 View Post
I have:

Code:
Public Class Form1
    Private Sub btnStartDiscoShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartDiscoShow.Click
        Me.BackColor = Color.Black
        Me.Refresh()
        System.Threading.Thread.Sleep(50)
        Me.Refresh()
        System.Threading.Thread.Sleep(50)
        Me.BackColor = Color.Red
        Me.Refresh()
        System.Threading.Thread.Sleep(50)
        Me.BackColor = Color.Yellow
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.BackColor = Color.Black
    End Sub
End Class
I'm using black, red, and yellow so I can see them better. Darkblue and black you may not see the change.

And thanks Nextgen.

EDIT: Just tested yours out Nextgen and it works quite well. Thanks!
Not a problem, and the good news is that method has been around since the beginning of basic, so it is old and trustworthy, plus will work with selecting any random outcome and displaying it.
hey shark try out this

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.BackColor = Color.Black
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Me.BackColor = Color.Black
Me.Refresh()
System.Threading.Thread.Sleep(250)
Me.Refresh()
System.Threading.Thread.Sleep(250)
Me.BackColor = Color.Red
Me.Refresh()
System.Threading.Thread.Sleep(250)
Me.BackColor = Color.Yellow
End Sub

End Class
Hopefully I can remember that for next time!

Off topic slightly:
To zman: Is that all it is or does the project have more?
Posts 115 of 20 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?