Cambiar el color de fondo de un botón

I have a problem with changing the color of a button (in I have searched the web and plenty of people are willing to tell me HOW TO change the color but my problem is - it doesn't. I say it doesn't, it does when it has finished the rest of the code in the Sub. Can anyone furnish me with an explanation please as to why it doesn't happen when I ask? I'm using Visual Studio 2008

preguntado el 10 de marzo de 12 a las 08:03

2 Respuestas

After changing the colour call Application.DoEvents()

This gives the GUI a chance to update.

respondido 10 mar '12, 09:03

Perfect. Exactly as it says on the tin. Now have to go research this command. Thanks for your time & trouble. - Nick Salmon

Application.DoEvents will work, but it's the wrong solution for this.

The right solution has to do with the reason you don't want to wait for the end of the sub: you have some long running code in your method, and the method run in direct response to a UI event. In this situation, the Derecho La solución es usar un FondoTrabajador component to execute the long-running code, so the method will complete right away and the button can change color when it's supposed to.

respondido 10 mar '12, 15:03

Hi Joe, sorry only just seen your answer. The reply that Velox gave me helped a lot but I will certainly investigate the BackgroundWorker. Many thanks - Nick Salmon

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.