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();
            }
        }
    }
    
    

    运行:

  • 相关阅读:
    SVN中建立项目
    Dojo 学习笔记 之 Dojo hitch&partial
    Javascript的“上下文”(context)
    栅格那点儿事(四E)
    栅格那点儿事(四D)
    栅格那点儿事(四C)
    Sqoop Import数据库时中文乱码解决方案
    Sqoop架构
    Sqoop环境安装
    Sqoop概述
  • 原文地址:https://www.cnblogs.com/lz32158/p/12968870.html
Copyright © 2011-2022 走看看