When does imageindex actually update the button image?

Good day all!

I'm brand new to Visual C#, so this is likely a beginner question, but it's stumping me. I am trying to create a button that, when you click it, it changes the button image for a couple of seconds, then reverts it to normal. I loaded up an image index with several pictures to use, but am getting a strange issue. When the button is clicked on, it waits the amount of time I request (2 seconds), but the picture never changes. (I know it goes through the code, because it does other things unrelated to the button at the same time.) The code is really as basic as (forgive capitalization issues):

button1.imagendex = 6;
thread.delay(2000);
// some other code happens here totally unrelated to the button
button1.imageindex = 10;

I'm trying to figure out if this is an issue where the actual screen refresh does not occur while the code is going on, or if maybe the image index change isn't seen while the button is still "clicked," or some other issue.

Does anyone have any ideas?

Ray

[1034 byte] By [RayPowers] at [2007-12-22]
# 1

The reason that it is never changing visibly is because you haven't given it a chance to as when fire off your sleep/delay you are preventing the window from being repainted, something that wont happen ordinarily until the original method that was called because of your button press has returned.

One quick and easy way to get around this is to force the environment to process all outstanding window messages and repaint the form if needed... in order to do that simply fire off an Application.DoEvents() after you've changed your UI element but before you put the method to sleep for a moment or two.

BrendanGrant at 2007-8-30 > top of Msdn Tech,Visual C#,Visual C# General...
# 2

I'll give that a try, it sounds like exactly what I need. Thank you!

Ray

RayPowers at 2007-8-30 > top of Msdn Tech,Visual C#,Visual C# General...