Progress Bar in StatusBar control issue

I am using the code below to create a Progress bar in my status bar on my MDI parent form.  The code works well.  However, when it is finished I want to reset the progress panel to its original state and cannot figure out how to do it.  How do I get the panel's color back to windows gray.  Any ideas

Thanks,

Mike

//**************Code for Initializing progressbar and panel*******************
this.statusBar1 = new ProgressStatusBar();
this.panelStatus = new System.Windows.Forms.StatusBarPanel();
this.panelProgress = new ProgressPanel();
//**************Code for ProgressStatusBar*******************
public class ProgressStatusBar : System.Windows.Forms.StatusBar
{
public ProgressStatusBar()
{
this.SizingGrip = false;
this.ShowPanels = true;
}

protected override void OnDrawItem(StatusBarDrawItemEventArgs e)
{
if (e.Panel.GetType().ToString().EndsWith("ProgressPanel"))
{
ProgressPanel ProgressPanel = (ProgressPanel) e.Panel;
if (ProgressPanel.Value > ProgressPanel.Minimum)
{
int NewWidth = (int)(((double)ProgressPanel.Value /
(double)ProgressPanel.Maximum) * (double)ProgressPanel.Width);
Rectangle NewBounds = e.Bounds;
SolidBrush PaintBrush = new SolidBrush(ProgressPanel.ForeColor);
NewBounds.Width = NewWidth;
e.Graphics.FillRegion(PaintBrush, new Region(NewBounds));
PaintBrush.Dispose();
}
else
{
base.OnDrawItem(e);
}
}
else
{
base.OnDrawItem(e);
}
}

public void UpdateValue(ProgressPanel ProgressPanel, int NewValue)
{
ProgressPanel.Value = NewValue;

}
}

public class ProgressPanel : System.Windows.Forms.StatusBarPanel
{
private int m_Minimum = 1;
private int m_Maximum = 100;
private int m_Value = 0;
private Color m_Color;

public ProgressPanel()
{
this.Style = StatusBarPanelStyle.OwnerDraw;
this.ForeColor = Color.Blue;
}

public int Minimum
{
get { return m_Minimum; }
set { m_Minimum = value; }
}

public int Maximum
{
get { return m_Maximum; }
set { m_Maximum = value; }
}

public int Value
{
get { return m_Value; }
set { m_Value = value; }
}

public Color ForeColor
{
get { return m_Color; }
set { m_Color = value; }
}
}


Answer this question

Progress Bar in StatusBar control issue

  • Dopi

    Ken,

    Thanks for your input.  That did the job.  I thought I had tried that and it didn't work, but it worked this time.

    Mike

  • danmbuen

    Not to restate the obvious, but if you set the Value property of the ProgressPanel control to its Minimum property value, doesn't it look right  I tried your code, and this works fine for me. Is there something else you're looking for  
  • Lion Laon

    Vasil,

    I have created a sample project called DemoProgressStatusBar which can be downloaded from my website at 

    http://www.sqlscriptsafe.com/MiscSampleCode.aspx

    It includes a working copy of the progress status bar.  The code included in the project is taken directly from my shareware tool SQL ScriptSafe.  It is still in Beta, but please feel free to download a copy to try at http://www.sqlscriptsafe.com 

    Mike


  • Boris Drajer

    Vasil,

    Sorry for the oversight.  I am not sure how that happened.  However, I have included the missing file in the .zip file that is on the site now.  FYI, the file is at 

    http://www.sqlscriptsafe.com/miscsamplecode.aspx

    Mike

  • Wolfgang.999

    Hi Mike,
    Thanks for your collaboration. I've downloaded the ZIP file but the ProgressStatusBar.cs file is missing so I can't test it correctly. Please include it in your project.

    Vasil

  • timbop88

    Hi Mike,

    I've tried to test your code bu I can't set the code and controls on my form. Would you like to send me the sample project or just make reply on this message with it.

    Tnx,
    Vasil

  • Progress Bar in StatusBar control issue