zoukankan      html  css  js  c++  java
  • 31.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 WindowsFormsApp2 {
        public partial class Form1 : Form {
            public Form1() {
                InitializeComponent();
            }
    
            private void timer1_Tick(object sender, EventArgs e) {
    
                label1.Text  =label1.Text.Substring(1) + label1.Text.Substring(0, 1);
            }
        }
    }
    
    

    定时播放音乐


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Media;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace WindowsFormsApp2 {
        public partial class Form1 : Form {
            public Form1() {
                InitializeComponent();
            }
    
            private void timer1_Tick(object sender, EventArgs e) {
    
                label1.Text  =label1.Text.Substring(1) + label1.Text.Substring(0, 1);
            }
    
            /// <summary>
            /// 每隔1秒钟就把当前时间赋值给label
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void timer2_Tick(object sender, EventArgs e) {
    
                lblTime.Text = DateTime.Now.ToString();
    
                //22:10播放音乐
                if (DateTime.Now.Hour == 22 && DateTime.Now.Minute == 10 && DateTime.Now.Second == 50) {
    
                    //播放音乐
                    SoundPlayer sp = new SoundPlayer();
                    sp.SoundLocation = @"C:Users22053Desktop1.wav";
                    sp.Play();
                }
            }
    
            /// <summary>
            /// 当窗体加载的时候,将当前系统的时间赋值给Label
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void Form1_Load(object sender, EventArgs e) {
                lblTime.Text = DateTime.Now.ToString();
            }
        }
    }
    
    

    运行:

  • 相关阅读:
    多线程之缓存一致性协议
    Redis基础入门-linux安装
    Linux 上传文件rz 命令提示 -bash: rz: command not found 问题解决办法
    面试题之十亿条记录,怎么获取出现最多的前十个
    设计模式之工厂设计模式
    设计模式之单例设计模式
    数据结构之红黑树
    Eclipse使用Maven创建web3.0项目
    Eclipse创建Maven工程报错
    Oracle中的commit详解
  • 原文地址:https://www.cnblogs.com/lz32158/p/12968870.html
Copyright © 2011-2022 走看看