WinForms 持續滾動的進度條

TL;DR
持續執行的進度條
  
        ProgressBar progressBar = new ProgressBar();
        progressBar.Style = ProgressBarStyle.Marquee;
        progressBar.MarqueeAnimationSpeed = 10;


停止:
  
progressBar.Style = ProgressBarStyle.Continuous;
progressBar.MarqueeAnimationSpeed = 0;



完整程式碼範例:
  

    public Form1()
    {
        ProgressBar progressBar = new ProgressBar();
        progressBar.Size = new Size(500, 30);
        progressBar.Location = new Point(10, 10);
        this.Controls.Add(progressBar);

        Button button = new Button();
        button.Text = "Start";
        button.Location = new Point(progressBar.Right + 10, 10);
        button.Size = new Size(100, 30);
        button.Click += (sender, e) =>
        {
            if (button.Text.Equals("Start"))
            {
                button.Text = "Stop";
                progressBar.Style = ProgressBarStyle.Marquee;
                progressBar.MarqueeAnimationSpeed = 10;
            }
            else
            {
                button.Text = "Start";
                progressBar.Style = ProgressBarStyle.Continuous;
                progressBar.MarqueeAnimationSpeed = 0;
            }
        };
        this.Controls.Add(button);
    }



留言