额,我也试着做了下,用Winform的Timer组件,分享。。
- 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;
- namespace 点击按钮滚动
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- bool left;//控制做循环
- bool right;//控制右循环
- int count;//次数
- private void btnLeft_Click(object sender, EventArgs e)//点击左移
- {
- left = true;
- right = false;
- count=0;//将count值清零
- timer1.Enabled = true;//启用组件
- }
- private void btnRight_Click(object sender, EventArgs e)//点击右移
- {
- left = false;
- right = true;
- count = 0;
- timer1.Enabled = true; //启用组件
- }
- private void Form1_Load(object sender, EventArgs e)//加载窗体
- {
- textBox1.Text = "请输入你要滚动的文字";
- timer1.Enabled = false;//将Timer组件禁用
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- string str = textBox1.Text;
- if(left)
- {
- textBox1.Text = str.Substring(1, str.Length - 1) + str[0];
- count++;
- }
- else if(right)
- {
- textBox1.Text = str[str.Length - 1] + str.Substring(0, str.Length - 1);
- count++;
- }
- if (count >= textBox1.Text.Length)//当次数大于等于当前文本的长度时
- {
- timer1.Enabled = false;//将Timer组件禁用
- }
- }
- }
- }
复制代码 |