面向对象winform版小闹钟

winform窗口

namespace 闹钟2
{
public partial class Form1 : Form
{
//BlockLibarary.Block bb = new BlockLibarary.Block();
//public Form1()
//{
//    InitializeComponent();
//}

//private void button1_Click(object sender, EventArgs e)
//{
//    if (openFileDialog1.ShowDialog() == DialogResult.OK)
//    {
//        textBox2.Text = openFileDialog1.FileName;
//    }
//}

//private void button2_Click(object sender, EventArgs e)
//{
//    bb.BlockTime =Convert.ToDateTime( textBox1.Text).ToString(“yyyy-MM-dd hh:mm:ss”);
//    bb.BlockBgSound = textBox2.Text;
//    MessageBox.Show(“设定成功”);
//}

//private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
//{

//}

//private void timer1_Tick(object sender, EventArgs e)
//{
//    if (bb.IsPlay() == true)
//    {
//        axWindowsMediaPlayer1.URL = bb.BlockBgSound;
//        axWindowsMediaPlayer1.Ctlcontrols.play();
//    }
//    else { }
//}
//重写dll方法闹钟延迟十秒执行
覆盖dll dd = new 覆盖dll();
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)//浏览选背景乐
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox2.Text = openFileDialog1.FileName;
}
}

private void button2_Click(object sender, EventArgs e)//设定
{
dd.BlockTime = Convert.ToDateTime(textBox1.Text).ToString(“yyyy-MM-dd hh:mm:ss”);
dd.BlockBgSound = textBox2.Text;
MessageBox.Show(“设定成功”);
}

private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
{

}

private void timer1_Tick(object sender, EventArgs e)//timmer控件(至于timmer控件的开启可以放到设定按钮的事件中)
{
if (dd.IsPlay() == true)
{
axWindowsMediaPlayer1.URL = dd.BlockBgSound;
axWindowsMediaPlayer1.Ctlcontrols.play();
}
else { }
}

}
}

类的重写

 

namespace 闹钟2
{
//要重写dll中的类就要继承
class 覆盖dll:BlockLibarary.Block
{
public override bool IsPlay()
{
DateTime sheiding =Convert.ToDateTime( this.BlockTime);//设定时间
DateTime now = DateTime.Now;
TimeSpan xiang = now.Subtract(sheiding);
if (xiang.Seconds == 10)
{
return true;
}
else { return false; }
}
}
}

标签