namespace WindowsBlock
{public partial class Form1 : Form
{
UseBlock myblock = new UseBlock();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult result=openFileDialog1.ShowDialog();
if(result.ToString().ToLower()=="ok")
{
this.txtBgSound.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.txtBgSound.Text;
myblock.BlockText = this.txtText.Text;
MessageBox.Show("設定成功");
}
private void timer1_Tick(object sender, EventArgs e)
{
if(myblock.IsPlay()==true)
{
axWindowsMediaPlayer1.URL=myblock.BlockBgSound;
axWindowsMediaPlayer1.Ctlcontrols.play();
MessageBox.Show(myblock.BlockText);
}
}
}
}
----------------------------------------------------------------------------------------------------------
namespace BlockLibrary
{
public class Block
{
public string BlockTime { get; set; }
public string BlockBgSound { get; set; }
public virtual bool IsPlay()
{
if (BlockTime == DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"))
{
return true;
}
return false;
}
}
}
----------------------------------------------------------------------------------------------------------
namespace BlockLibrary
{
public class UseBlock:BlockLibrary.Block
{
public string BlockText { get; set; }
public override bool IsPlay()
{
DateTime useblock = Convert.ToDateTime(this.BlockTime);
DateTime nowtime = DateTime.Now;
TimeSpan span = nowtime.Subtract(useblock);
if (span.Seconds==10)
{
return true;
}
return false;
}
}
}