日期:2014-05-18 浏览次数:21167 次
public class DrawStringControl : PictureBox
    {
        float moveSize = 0.5F;
        float CurrentPost = -10F;
        private Graphics g;//
        public DrawStringControl()
        {
            timer1 = new Timer();
            timer1.Interval = Interval;
            timer1.Tick +=new EventHandler(timer1_Tick);
        }
        private Timer timer1;
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            g = pe.Graphics;
            PointF p = new PointF(CurrentPost,0F);//
            g.DrawString(Value, new Font("宋体", 15), Brushes.Red, p);
        }
        /// <summary>
        /// 开始滚动
        /// </summary>
        public void Start()
        {           
            timer1.Start();
        }
        public void Stop()
        {
            timer1.Stop();
        }
     
        /// <summary>
        /// 向上移动的大小
        /// </summary>
        public float MoveSize
        {
            get { return moveSize; }
            set { moveSize = value; }
        }
        private int interval = 10;
        /// <summary>
        /// 多长时间移动一次
        /// </summary>
        public int Interval
        {
            get { return interval; }
            set { interval = value; }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            CurrentPost -= moveSize;        
            PointF p = new PointF(CurrentPost, 0F);//左移动
            g.DrawString(Value, new Font("宋体", 12), Brushes.Red, p);
        }
        private string value;
       /// <summary>
       /// 要画的文本
       /// </summary>
        public string Value
        {
            get { return this.value; }
            set
            {
                this.value = value;
            }
        }
       
    }