码迷,mamicode.com
首页 > 其他好文 > 详细

文本框的走马灯效果

时间:2016-05-03 16:11:52      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

界面设计:

技术分享

拖动timer控件进来

技术分享

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

技术分享

具体代码如下:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 
11 namespace 走马灯
12 {
13     public partial class Form1 : Form
14     {
15         public Form1()
16         {
17             InitializeComponent();
18         }
19         //定义一个全局变量,用于指示走马灯的方向
20         string flag = "";
21         //此处为每隔指定时间时间控件激发的事件
22         private void timer1_Tick(object sender, EventArgs e)
23         {
24             //运行自定义的run方法
25             run();
26         }
27         //向左滚动按钮
28         private void button1_Click(object sender, EventArgs e)
29         {
30             //指示走马灯方向
31             flag = "left";
32             //时间控件启用
33             timer1.Enabled = true;
34         }
35 
36         private void button2_Click(object sender, EventArgs e)
37         {
38             //指示走马灯方向
39             flag = "right";
40             //时间控件启用
41             timer1.Enabled = true;
42         }
43         //自定义的run方法
44         public void run()
45         {
46             //如果指示方向是左
47             if (flag == "left")
48             {
49                 //字符串的截取拼接
50                 textBox1.Text = textBox1.Text.Substring(1, (textBox1.Text.Length - 1)) + textBox1.Text.Substring(0, 1);
51             }
52             //如果指示方向是右
53             else if (flag == "right")
54             {
55                 //字符串的截取拼接
56                 textBox1.Text = textBox1.Text.Substring(textBox1.Text.Length - 1, 1) + textBox1.Text.Substring(0,textBox1.Text.Length-1);
57             }
58         }
59 
60 
61     }
62 }

 

文本框的走马灯效果

标签:

原文地址:http://www.cnblogs.com/start-from-scratch/p/5455205.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!