Marquee. Indicates progress by continuously scrolling a block across a ProgressBar in a marquee fashion. Use Marquee when you can't specify a quantity of progress, but still need to indicate that progress is being made.
To create a ProgressBar control at design-time, you simply drag a ProgressBar control from the Toolbox and drop onto a Form in Visual Studio. After you the drag and drop, a ProgressBar is created on the Form; for example the ProgressBar1 is added to the form and looks as in Figure 1.
A progress bar is a control that an application can use to indicate the progress of a lengthy operation such as calculating a complex result, downloading a large file from the Web etc.
You can update the percentage of progress displayed by using the setProgress(int) method, or by calling incrementProgressBy(int) to increase the current progress completed by a specified amount. By default, the progress bar is full when the progress value reaches 100.
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.
To start/stop the animation, you should do this:
To start:
progressBar1.Style = ProgressBarStyle.Marquee;
progressBar1.MarqueeAnimationSpeed = 30;
To stop:
progressBar1.Style = ProgressBarStyle.Continuous;
progressBar1.MarqueeAnimationSpeed = 0;
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.
This code is a part of a login form where the users wait for the authentication server to respond.
using System;
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;
namespace LoginWithProgressBar
{
public partial class TheForm : Form
{
// BackgroundWorker object deals with the long running task
private readonly BackgroundWorker _bw = new BackgroundWorker();
public TheForm()
{
InitializeComponent();
// set MarqueeAnimationSpeed
progressBar.MarqueeAnimationSpeed = 30;
// set Visible false before you start long running task
progressBar.Visible = false;
_bw.DoWork += Login;
_bw.RunWorkerCompleted += BwRunWorkerCompleted;
}
private void BwRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// hide the progress bar when the long running process finishes
progressBar.Hide();
}
private static void Login(object sender, DoWorkEventArgs doWorkEventArgs)
{
// emulate long (3 seconds) running task
Thread.Sleep(3000);
}
private void ButtonLoginClick(object sender, EventArgs e)
{
// show the progress bar when the associated event fires (here, a button click)
progressBar.Show();
// start the long running task async
_bw.RunWorkerAsync();
}
}
}
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).
Many good answers here already, although you also need to keep in mind that if you are doing long-running processing on the UI thread (generally a bad idea), then you won't see the marquee moving either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With