Computers/Language 2012. 9. 7. 16:24

C# 다른 창에서 프로그레스  바 띄우기

단일 폼 SDI 에서 다른 창에 상태 진행 바 표시하는 방법


1. 프로젝트 명에서 우측 마우스 - 추가 - 윈도우 폼

2. 아래 코드 삽입

namespace WindowsFormsApplication1

{

    public partial class ReWindow : Form

    {

        public RefuelWindow()

        {

            InitializeComponent();

            progressBarRefuel.Maximum = 100;

            progressBarRefuel.Minimum = 0;

        }

        public void UpdateProgressBar(int counter5min, int counter5minINIT, string message, string status)

        {

            progressBarRefuel.Value = ((counter5minINIT - counter5min) * 100) / counter5minINIT;

            tbTimeClock.Text = (counter5min / 60).ToString() + ":" + (counter5min % 60).ToString("D2");

            tbStationStatus.Text = message;

            tbStationStatus.Text = status;

            if (counter5min == 0) this.Close();

        }

    }

}


3. 그리고 원 폼에서 아래처럼 부르면 된다. 즉 폼을 만들고 함수 콜 ~~

            ReWindow progStatus = new ReWindow();

            progStatus.Show();






열심히 구글링 해서 얻은 정보는 아래


http://stackoverflow.com/questions/7302761/update-progressbar-in-another-window-from-a-function


Update ProgressBar in another window from a function?

소스는 아래라고 했는뎅...
ProgressWindows progForm = new ProgressWindows();
//progForm.fileProgress1
public void UpdateProgressBar(int percentage)
{
   
// Set the progress in the progress bar.
    fileProgress1
.Percentage = percentage;
}
ProgressWindows progForm = new ProgressWindows();
progForm
.UpdateProgressBar(percentage);
실제로는 아래 코드사용
// ------------------------------- Pop up window -------------
int PortNumbers = portNames.Count(), ndx = 1;
string SearchMessage = "Searching CARD Reader ...";
ProgressWindow progStatus = new ProgressWindow();
progStatus.Show();
// ------------------------------- Pop up window -------------
foreach (string cPorts in portNames)
{
try
{
progStatus.UpdateProgressBar((ndx * 100) / PortNumbers, SearchMessage);
                    ndx++;

posted by 털보네i
: