How to control the speed of device simulation

myxsys

New member
Joined
Aug 25, 2006
Messages
3
Location
Kenya
Programming Experience
1-3
Hi,

Am doin this project that is suppose to simulate to a person how a storage device works. Am using a Panel to represent the device and a number of labels to represent the cells in the device. Each cell represents a single character.

When text is entered into a dialog box, the program is suppose to show the text being saved in the cells. I do this by just changing the color of the labels that will be affected.

However, this process is done very fast. I need to be able to control the speed at which the labels change color. I,ve tried inserting the code Thread.sleep(500) into my "Change color" loops but my program just hangs momentarily then executes at normal speed.

Please Help!

Thanks in advance.
 
Ok, you could do this in a loop ( or atleast i think so in my head) You'll need the RGB values of the current cell/label backcolor and the RGB values of the color you want the label/Cell to be. Define an increment for each of the RGB values and add them in the For/Next Loop. The following code will slowly change the color of a label with a black backcolor to white. A timer could also be usful in this instance...

VB.NET:
Dim Increment As Integer = 1
Dim R, G, B As Integer
R = 0
G = 0
B = 0
Label1.BackColor = Color.Black
Application.DoEvents()
For i AsInteger = 1 To 255
R += Increment
B += Increment
G += Increment
Label1.BackColor = Color.FromArgb(R, G, B)
Application.DoEvents()
System.Threading.Thread.Sleep(10)
Next
 
Thanks for the help but having tried your idea, it wasn't what I was going
for. For clarity, let me illustrate an example:

'Assuming on my form I have placed a Panel called myPanel and
already contains a number of labels, say 16 labels. I used the following code to demonstrate data being stored in the cells by changing the label color.

Dim currentCell as Label
For Each currentCell In MyPanel.Controls
With currentCell
.BackColor = Color.Chartreuse
End With
MessageBox.show("Cell has changed color!")
Next

The above code changes the BackColor of every Label. However, one has to
click the Message boxes for every change in color. You will notice that
changing of BackColor goes Label by Label at a time.
I would like to achieve this effect but without using the MessageBox. I had
already tried to use the Thread.sleep(500) but I got unexpected results.

Please help, I am open to any suggestions.

Note: The Label.Backcolor.R = R brings up an error, A better alternative I discovered was to use:
Label.BackColor = Color.FromArgb(R, G, B)
 
Thread.sleep works fine for this but you missed the point of using Application.DoEvents in this combination, myxsys. Read vis781 code example again.
 
Back
Top