文本滚动和计时

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;//计时相关

namespace 文本的滚动
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //可以初始化form上的控件
            textBox1.Text = "huaimaomaopolanlan";
        }

        private void btnLeft_Click(object sender, EventArgs e)
        {
            
            for(int i = 0; i  < textBox1.Text.Length;i++)
            {
                //              取从第二个开始的剩余部分      取第一个字
                textBox1.Text = textBox1.Text.Substring(1) +  textBox1.Text.Substring(0, 1);
                System.Threading.Thread.Sleep(500);
                textBox1.Update();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Stopwatch watch = new Stopwatch();
            watch.Start();
            for( int i = 0; i <= 1000;  i++)
            {
                textBox2.Text = i.ToString();
                //textBox2.Update();
            }
            watch.Stop();
            MessageBox.Show(string.Format("用时为:{0}", watch.Elapsed.Milliseconds));
        }

        private void btnRight_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < textBox1.Text.Length; i++)
            {
                //              取最后一个字                                       取剩余部分
                textBox1.Text = textBox1.Text.Substring(textBox1.Text.Length -1) + textBox1.Text.Substring(0, textBox1.Text.Length-1);
                System.Threading.Thread.Sleep(500);//0.5秒
                textBox1.Update();
            }
        }
    }
}

 

 

 

posted @ 2017-08-01 10:53  mCat  Views(130)  Comments(0Edit  收藏  举报