C# Code
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
using
System;
using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace 走马灯 { public partial class Form1 : Form { int flag = 0 ; public Form1() { InitializeComponent(); } //要求: //当点击左移按钮的时候不断左移,当点击右移按钮的时候不断右移,当点击暂停按钮的时候暂停 private void button1_Click( object sender, EventArgs e) { flag = 1 ; //左移 //while (flag == 1) //{ // string Input = textBox1.Text; // char leftInput = Input[0]; // string ringhtInput = Input.Substring(1); // textBox1.Text = ringhtInput + leftInput; //} } private void button2_Click( object sender, EventArgs e) { flag = 2 ; //右移 //while (flag == 2) //{ // string Input = textBox1.Text; // char leftInput = Input[Input.Length - 1]; // string ringhtInput = Input.Substring(0, Input.Length - 1); // textBox1.Text = leftInput + ringhtInput; //} } private void btnpause_Click( object sender, EventArgs e) { flag = 0 ; //暂停 } private void timer1_Tick( object sender, EventArgs e) //在timer的tick事件中写 { if (flag == 1 ) { //不断取出第一位移到最后一位后面 string Input = textBox1.Text; char leftInput = Input[ 0 ]; string ringhtInput = Input.Substring( 1 ); textBox1.Text = ringhtInput + leftInput; } if (flag == 2 ) { //不断取出最后一位移到第一位前面 string Input = textBox1.Text; char leftInput = Input[Input.Length - 1 ]; string ringhtInput = Input.Substring( 0 , Input.Length - 1 ); textBox1.Text = leftInput + ringhtInput; } } } } |