Windows Forms ProgressBar : 선택 윤곽을 시작 / 중지하는 가장 쉬운 방법?
C # 및 Windows Forms를 사용하고 있습니다. 프로그램에서 정상적인 진행률 표시 줄이 제대로 작동하지만 이제는 기간을 쉽게 계산할 수없는 다른 작업이 있습니다. 진행률 표시 줄을 표시하고 싶지만 스크롤 선택 윤곽을 시작 / 중지하는 가장 좋은 방법을 모르겠습니다. 나는 윤곽 속도를 설정하고 start () 및 stop ()을 갖는 것과 같은 간단한 것을 기대했지만 그렇게 간단하지 않은 것 같습니다. 백그라운드에서 빈 루프를 실행해야합니까? 어떻게하면 좋을까요? 감사
스타일이로 설정된 진행률 표시 줄을 사용합니다 Marquee
. 이것은 불확실한 진행률 표시 줄을 나타냅니다.
myProgressBar.Style = ProgressBarStyle.Marquee;
MarqueeAnimationSpeed
속성을 사용 하여 진행률 표시 줄에서 작은 색상 블록을 애니메이션하는 데 걸리는 시간을 설정할 수도 있습니다 .
애니메이션을 시작 / 중지하려면 다음을 수행해야합니다.
시작한다:
progressBar1.Style = ProgressBarStyle.Marquee;
progressBar1.MarqueeAnimationSpeed = 30;
그만하다:
progressBar1.Style = ProgressBarStyle.Continuous;
progressBar1.MarqueeAnimationSpeed = 0;
작동 방식이 아닙니다. 선택 윤곽 스타일 진행률 표시 줄을 표시하여 "시작"하고 숨기면 중지합니다. Style 속성을 변경할 수 있습니다.
이 코드는 사용자가 인증 서버의 응답을 기다리는 로그인 양식의 일부입니다.
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();
}
}
}
MSDN에이 주제에 대한 코드 가 포함 된 멋진 기사 가 있습니다. Style 속성을 ProgressBarStyle.Marquee로 설정하는 것이 적절하지 않다고 가정하고 있습니다 (또는 제어하려는 것이 맞습니까 ??-속도를 제어 할 수 있지만이 애니메이션을 중지 / 시작할 수 없다고 생각합니다. @Paul이 나타내는대로).
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.
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 :-)
'Development Tip' 카테고리의 다른 글
jar 파일에는 정확히 무엇이 포함됩니까? (0) | 2020.10.28 |
---|---|
pyspark에서 Dataframe 열을 String 유형에서 Double 유형으로 변경하는 방법 (0) | 2020.10.28 |
작은 메모리에서 실행되는 사용 가능한 대화 형 언어는 무엇입니까? (0) | 2020.10.27 |
Google 크롬 확장 프로그램에서 프로그래밍 방식으로 devtools를 열 수 있나요? (0) | 2020.10.27 |
때때로`git stash -p`가 실패하는 이유는 무엇입니까? (0) | 2020.10.27 |