views:

13243

answers:

6

I am using C# and Windows Forms. I have a normal progress bar working fine in the program, but now I have another operation where the duration cannot be easily calculated. I would like to display a progress bar but don't know the best way to start/stop the scrolling marquee. I was hoping for something as simple as setting the marquee speed and then having a start() and stop() but it doesn't appear to be that simple. Do I have to run an empty loop in the background? How do I best do this? Thanks

A: 

you can use a Timer (System.Windows.Forms.Timer).

Hook it's Tick event, advance then progress bar until it reaches the max value. when it does (hit the max) and you didn't finish the job, reset the progress bar value back to minimum.

...just like Windows Explorer :-)

Asher
A: 

There's a nice article with code on this topic on MSDN. I'm assuming that setting the Style property to ProgressBarStyle.Marquee is not appropriate (or is that what you are trying to control?? -- I don't think it is possible to stop/start this animation although you can control the speed as @Paul indicates).

tvanfosson
+8  A: 

Use a progress bar with the style set to Marquee. This represents an indeterminate progress bar.

myProgressBar.Style = ProgressBarStyle.Marquee;

You can also use the MarqueeAnimationSpeed property to set how long it will take the little block of color to animate across your progress bar.

Paul Fisher
+2  A: 

It's not how they work. You "start" a marquee style progress bar by making it visible, you stop it by hiding it. You could change the Style property.

Hans Passant
+4  A: 

Those who want to stop/start the animation should look at this:

To start: progressBar1.Style = ProgressBarStyle.Marquee; progressBar1.MarqueeAnimationSpeed = 30; To stop: progressBar1.Style = ProgressBarStyle.Continuous; progressBar1.MarqueeAnimationSpeed = 0;

You don't need to set `MarqueeAnimationSpeed` when stopping it, and when starting it, it usually has a reasonable value. No need to set it every time when starting.
icktoofay
A: 

Check out http://mycodelog.com/2010/02/11/busy/ for sample code on how to use Progress Bars (Marquee or Blocks) in Windows Forms.

Ali B