您的位置:首页 > 其它

文本框的走马灯效果

2016-05-03 15:41 363 查看
界面设计:



拖动timer控件进来



设置拖进来的timer控件的Tick事件



具体代码如下:

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();
}
//定义一个全局变量,用于指示走马灯的方向
string flag = "";
//此处为每隔指定时间时间控件激发的事件
private void timer1_Tick(object sender, EventArgs e)
{
//运行自定义的run方法
run();
}
//向左滚动按钮
private void button1_Click(object sender, EventArgs e)
{
//指示走马灯方向
flag = "left";
//时间控件启用
timer1.Enabled = true;
}

private void button2_Click(object sender, EventArgs e)
{
//指示走马灯方向
flag = "right";
//时间控件启用
timer1.Enabled = true;
}
//自定义的run方法
public void run()
{
//如果指示方向是左
if (flag == "left")
{
//字符串的截取拼接
textBox1.Text = textBox1.Text.Substring(1, (textBox1.Text.Length - 1)) + textBox1.Text.Substring(0, 1);
}
//如果指示方向是右
else if (flag == "right")
{
//字符串的截取拼接
textBox1.Text = textBox1.Text.Substring(textBox1.Text.Length - 1, 1) + textBox1.Text.Substring(0,textBox1.Text.Length-1);
}
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: