Using Progress Bar


#pragma once

namespace My6 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
///
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
///

public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
///
/// Clean up any resources being used.
///

~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::ProgressBar^ pgb1;
protected:
private: System::Windows::Forms::Button^ BtnStart;
private: System::Windows::Forms::Label^ lblPercent;
private: System::Windows::Forms::ProgressBar^ pgb2;
private: System::Windows::Forms::Timer^ t;
private: System::ComponentModel::IContainer^ components;
private:
///
/// Required designer variable.
///


#pragma region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
this->pgb1 = (gcnew System::Windows::Forms::ProgressBar());
this->BtnStart = (gcnew System::Windows::Forms::Button());
this->lblPercent = (gcnew System::Windows::Forms::Label());
this->pgb2 = (gcnew System::Windows::Forms::ProgressBar());
this->t = (gcnew System::Windows::Forms::Timer(this->components));
this->SuspendLayout();
//
// pgb1
//
this->pgb1->Location = System::Drawing::Point(12, 48);
this->pgb1->Name = L"pgb1";
this->pgb1->Size = System::Drawing::Size(502, 28);
this->pgb1->TabIndex = 0;
//
// BtnStart
//
this->BtnStart->Location = System::Drawing::Point(205, 127);
this->BtnStart->Name = L"BtnStart";
this->BtnStart->Size = System::Drawing::Size(127, 40);
this->BtnStart->TabIndex = 1;
this->BtnStart->Text = L"Start";
this->BtnStart->UseVisualStyleBackColor = true;
this->BtnStart->Click += gcnew System::EventHandler(this, &Form1::BtnStart_Click);
//
// lblPercent
//
this->lblPercent->AutoSize = true;
this->lblPercent->Location = System::Drawing::Point(235, 22);
this->lblPercent->Name = L"lblPercent";
this->lblPercent->Size = System::Drawing::Size(21, 13);
this->lblPercent->TabIndex = 2;
this->lblPercent->Text = L"0%";
//
// pgb2
//
this->pgb2->Location = System::Drawing::Point(12, 82);
this->pgb2->Name = L"pgb2";
this->pgb2->Size = System::Drawing::Size(502, 28);
this->pgb2->TabIndex = 3;
//
// t
//
this->t->Interval = 1;
this->t->Tick += gcnew System::EventHandler(this, &Form1::t_Tick);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(538, 170);
this->Controls->Add(this->pgb2);
this->Controls->Add(this->lblPercent);
this->Controls->Add(this->BtnStart);
this->Controls->Add(this->pgb1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
//Using Progress Bar
private: System::Void BtnStart_Click(System::Object^ sender, System::EventArgs^ e) {
pgb1->Value=0;
pgb2->Value=0;
t->Enabled=true;
BtnStart->Enabled=false;
}
private: System::Void t_Tick(System::Object^ sender, System::EventArgs^ e) {
pgb1->Value=pgb1->Value+1;
if(pgb1->Value==pgb1->Maximum)
{
pgb1->Value=pgb1->Minimum;
pgb2->Value=pgb2->Value+1;
lblPercent->Text=pgb2->Value.ToString()+"%";
if(pgb2->Value==pgb2->Maximum)
{
t->Enabled=false;
BtnStart->Enabled=true;
}
}
}
};
}