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
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).
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.
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.
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;
Check out http://mycodelog.com/2010/02/11/busy/ for sample code on how to use Progress Bars (Marquee or Blocks) in Windows Forms.