效果图
实现
代码
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();
}
}
}
运行: