views:

349

answers:

4

.NET newbie here... I'd like to make a button in a Windows form that displays a progress or "cooldown" effect. That is, when the button is pressed, it becomes disabled. As some event or timer is progressing, the button shows the progress graphically. When the progress is finished, the graphic completes and the button becomes enabled. Similar effects can be seen in many games.

I'd considered using a combination of the built in Button class, and the GDI+ DrawPath function, but the complexity scales poorly, and I get the nagging feeling that there must be an easier way.

Any ideas? Thanks.

+1  A: 

The easiest approach is to create an instance of the progress bar control and then you do not need to perform any custom coding/custom painting. If you really need to display everything inside the button control then you have two options. You can keep changing the Image property of the button or go the whole hog and perform custom painting of the button. Custom painting is pretty simple as you only need to draw Text plus whatever image you want.

Phil Wright
A: 

If you really need to have it on the button, I'd go with a custom paint event.

something similar to:

button += new buttonPaintEvent(buttonPaintEventHandlerMethod);
Fry
@Underflow: Care to elaborate on your solution using this answer?
Pat
+1  A: 

Another easy way might be to have two controls, a button and a progress bar that occupy the same space on the form. When the user presses the button, hide the button and show the progress bar. Update the progress bar as needed until whatever processing is done. Then, hide the progress bar and show the button again.

Greg Hewgill
A: 

I would not go the gdi route... Have you considered using wpf?

Tom Alderman