zoukankan      html  css  js  c++  java
  • 文本框的走马灯效果

    界面设计:

    拖动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 }
  • 相关阅读:
    Prime Ring Problem 素数环
    下沙的沙子有几粒?
    小兔的棋盘
    超级楼梯
    一只小蜜蜂...
    变形课
    Buy the Ticket
    How Many Trees?
    通过拦截器来统计每个action的执行时间
    apache+tomcat+session(JK实现方式)
  • 原文地址:https://www.cnblogs.com/start-from-scratch/p/5455205.html
Copyright © 2011-2022 走看看