鬧鐘類
Block.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassLibrary1
{
public class Block
{
public string BlockTime { get; set; }
public string BlockBgSound { get; set; }
public bool IsPlay()
{
if (BlockTime == DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"))
{
return true;
}
return false;
}
}
}
鬧鐘代碼
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;
using ClassLibrary1;
namespace 鬧鐘
{
public partial class Form1 : Form
{
BlockLibarary.Block myblock = new BlockLibarary.Block();
//Block myblock = new Block();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
if (result.ToString().ToLower() == "ok")
{
this.textBox1.Text = openFileDialog1.FileName;
}
}
private void button2_Click(object sender, EventArgs e)
{
myblock.BlockTime = Convert.ToDateTime(this.txttime.Text).ToString("yyyy-MM-dd hh:mm:ss");
myblock.BlockBgSound = this.txttime.Text;
MessageBox.Show("設定成功");
}
private void timer1_Tick(object sender, EventArgs e)
{
if (myblock.IsPlay()==true)
{
axWindowsMediaPlayer1.URL = myblock.BlockBgSound;
axWindowsMediaPlayer1.Ctlcontrols.play();
}
}
}
}