ProgressBar显示滚动的文字的问题?最好有代码。我怎么实验都不行呀,郁闷呀。
谢谢啦

解决方案 »

  1.   

    ProcessBar不能重写,只能自己写个控件来实现
      

  2.   

    参考
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Text;
    using System.Windows.Forms;namespace GameProcessBar
    {
        public partial class GameProcessBar : UserControl
        {
            public GameProcessBar()
            {
                InitializeComponent();
            }        int min = 0;
            int max = 100;
            int val = 0;
            Image im;
            protected override void OnResize(EventArgs e)
            {
                this.Invalidate();
            }        protected override void OnPaint(PaintEventArgs e)
            {
                if (im == null)
                    im = BackImage.BackgroundImage;            this.BackgroundImage = im;            SolidBrush myBrush = new SolidBrush(Color.GhostWhite);
                Graphics g = e.Graphics;
                float percent = (float)(val - min) / (max - min);
                Rectangle rect = this.ClientRectangle;            rect.Width = (int)((float)rect.Width * percent);            //g.DrawImage(im,rect,rect,GraphicsUnit.Pixel);
                g.FillRectangle(myBrush, rect);            //int mini = (max - val) / 60;
                //int sec = (max - val) % 60;
                //string text = string.Format("{0} 分 {1} 秒", mini, sec);
                //Font font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                //g.DrawString(text, font, Brushes.Black, 140, 5);
                Draw3DBorder(g);            myBrush.Dispose();
                g.Dispose();
            }        public int Minimum
            {
                get
                {
                    return min;
                }
                set
                {
                    if (value < 0)
                    {
                        min = 0;
                    }
                    if (value > max)
                    {
                        max = value;
                    }
                    min = value;
                    if (val < min)
                    {
                        val = min;
                    }
                    this.Invalidate();
                }
            }        public int Maximum
            {
                get
                {
                    return max;
                }
                set
                {
                    if (value < min)
                    {
                        min = value;
                    }
                    max = value;
                    if (val > max)
                    {
                        val = max;
                    }
                    this.Invalidate();
                }
            }        public int Value
            {
                get
                {
                    return val;
                }
                set
                {
                    int oldVal = val;
                    if (val < min)
                    {
                        val = min;
                    }
                    else if (val > max)
                    {
                        val = max;
                    }
                    else
                    {
                        val = value;
                    }                float percent;                Rectangle newValueRect = this.ClientRectangle;
                    Rectangle oldValueRect = this.ClientRectangle;                percent = (float)(val - min) / (max - min);
                    newValueRect.Width = (int)((float)newValueRect.Width * percent);                percent = (float)(oldVal - min) / (float)(max - min);
                    oldValueRect.Width = (int)((float)oldValueRect.Width * percent);                Rectangle updateRect = new Rectangle();                if (newValueRect.Width > oldValueRect.Width)
                    {
                        updateRect.X = oldValueRect.Size.Width;
                        updateRect.Width = newValueRect.Width - oldValueRect.Width;
                    }
                    else
                    {
                        updateRect.X = newValueRect.Size.Width;
                        updateRect.Width = oldValueRect.Width - newValueRect.Width;
                    }                updateRect.Height = this.Height;                this.Invalidate(updateRect);                int mini = (max - val) / 60;
                    int sec = (max - val) % 60;
                    label1.Text = string.Format("{0} 分 {1} 秒", mini, sec);
                }
            }        private void Draw3DBorder(Graphics g)
            {
                int PenWidth = (int)Pens.White.Width;            g.DrawLine(Pens.DarkGray, new Point(this.ClientRectangle.Left, this.ClientRectangle.Top),
               new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Top));
                g.DrawLine(Pens.DarkGray, new Point(this.ClientRectangle.Left, this.ClientRectangle.Top), new Point(this.ClientRectangle.Left, this.ClientRectangle.Height - PenWidth));
                g.DrawLine(Pens.White, new Point(this.ClientRectangle.Left, this.ClientRectangle.Height - PenWidth),
               new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Height - PenWidth));
                g.DrawLine(Pens.White, new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Top),
                new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Height - PenWidth));
            } 
        }
    }