ProgressStatusBar源代码(转自C#)

80酷酷网    80kuku.com

  status|源代码摘自:http://discuss.develop.com/
測試過,挺好的!

  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.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; }
                }
        }



分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: