我正好将代码整理出来,将下面代码copy到你的程序,直接使用UpdateValue就行了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()==typeof(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.DarkBlue;
                }                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; }
                }
        }

解决方案 »

  1.   

    我有一个更好的实现,其原理同上。设置你要显示进度条的 StatussBarPanel 的 Style 为 OwnerDraw 方式,利用其 Text 属性来保存进度值,因为是 String 类型,所以在重画时要转换为适当的数值型,在自画时利用此值和最大值来画出进度矩形。
    private void statusBar1_DrawItem(object sender, System.Windows.Forms.StatusBarDrawItemEventArgs sbdevent)
    {
    if (sbdevent.Panel == statusBarPanel1)
    {
    Graphics g = sbdevent.Graphics;
    float finishedPercent =  float.Parse(statusBarPanel1.Text);// 转换为ValueType
    int rectWidth = (int)( finishedPercent * (sbdevent.Bounds.Width-2) );

    g.FillRectangle( new SolidBrush(Color.DarkGoldenrod), sbdevent.Bounds.Left + 1, sbdevent.Bounds.Top + 2, rectWidth, sbdevent.Bounds.Height-4);
    }
    }然后在你的过程中使用以下两句来实现赋值和强制发生DrawItem事件。percent :你所要指定的值。
    this.statusBarPanel1.Text = percent.ToString();
    this.statusBar1.Refresh();我的方案都是这么做的,挺灵的。利用渐变刷可画出更好看的任务进度条。
      

  2.   

    能否把button,textbox等其它控件放在其上?