Monday, February 28, 2005

C#: progress bar in status

/// SNIPPET #1 ///
private ProgressBar m_ctrlProgress;
private System.Windows.Forms.StatusBarPanel panelProgress;
private void MainForm_Load(object sender, System.EventArgs e)
{
m_ctrlProgress = new ProgressBar();
m_ctrlProgress.SetBounds(104, 2, panelProgress.Width, statusBar.Height - 4); statusBar.Controls.Add(m_ctrlProgress);
m_ctrlProgress.Minimum = 0;
m_ctrlProgress.Maximum = 100;
m_ctrlProgress.Value = 0;
}
public void SetProgressRange(int nMin, int nMax)
{
m_ctrlProgress.Minimum = nMin;
m_ctrlProgress.Maximum = nMax;
}
public void SetProgressValue(int nValue)
{
m_ctrlProgress.Value = nValue;
}

/// SNIPPET #2 ///
// application level
ProgressStatusBar psb;
ProgressPanel pp;
public Form1() {
pp = new ProgressPanel();
pp.AutoSize = StatusBarPanelAutoSize.Spring;
psb = new ProgressStatusBar();
psb.Parent = this;
psb.Panels.AddRange(new ProgressPanel[] {pp});
ResizeRedraw = true;
this.Controls.Add(psb);
}

private void button1_Click(object sender, System.EventArgs e)
{
psb.UpdateValue(pp, pp.Value+10);
Invalidate(true);
}

No comments: