如何使用c#制作电脑报警 [英] how to make an pc alarm using c#
本文介绍了如何使用c#制作电脑报警的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用c#创建一个闹钟。我写了tahat代码,但我想添加mp3文件。我怎样才能做到这一点。请帮助我
使用系统;
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Windows.Forms;
使用 System.Media;
命名空间 aLARM_cLOCK
{
public partial class frmAlarm:表格
{
public frmAlarm()
{
InitializeComponent();
}
OpenFileDialog opd = new OpenFileDialog();
private void frmAlarm_Load( object sender,EventArgs e)
{
}
private void btnStart_Click( object sender,EventArgs e)
{
if (txtRoad.Text!= || txtTime.Text!= )
{
timer1.Start();
}
}
private void timer1_Tick( object sender,EventArgs e)
{
string now = DateTime.Now。 ToLongTimeString();
string WantedTime = txtTime.Text;
if (now == WantedTime)
{
SoundPlayer pleyer = new SoundPlayer();
pleyer.SoundLocation = opd.FileName;
pleyer.Play();
MessageBox.Show(txtMessage.Text);
}
}
private void btnRoad_Click( object sender,EventArgs e)
{
opd.Filter = 音乐文件|'。wav';
opd.ShowDialog();
txtRoad.Text = opd.FileName;
}
private void btnStop_Click(< span class =code-keyword> object sender,EventArgs e)
{
timer1.Stop();
}
}
}
解决方案
试试这个。
WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.URL = mp3 URL;
wplayer.controls.play();
Interop.WMPLib.dll您可以从以下网址下载,并为您的项目添加dll参考。 />
http://www.dllme。 com / dll / download / 22969 / Interop.WMPLib.dll [ ]
以下是示例代码的好示例
使用计时器创建简单的警报应用程序 [ ^ 一>
I want to create an alarm using c#. I wrote tahat code but I want to add mp3 file. How can I do this. Please help me
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 System.Media;
namespace aLARM_cLOCK
{
public partial class frmAlarm : Form
{
public frmAlarm()
{
InitializeComponent();
}
OpenFileDialog opd = new OpenFileDialog();
private void frmAlarm_Load(object sender, EventArgs e)
{
}
private void btnStart_Click(object sender, EventArgs e)
{
if (txtRoad.Text !="" || txtTime.Text !="")
{
timer1.Start();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
string now = DateTime.Now.ToLongTimeString();
string WantedTime = txtTime.Text;
if (now==WantedTime)
{
SoundPlayer pleyer = new SoundPlayer();
pleyer.SoundLocation = opd.FileName;
pleyer.Play();
MessageBox.Show(txtMessage.Text);
}
}
private void btnRoad_Click(object sender, EventArgs e)
{
opd.Filter = "file of music | '. wav'";
opd.ShowDialog();
txtRoad.Text = opd.FileName;
}
private void btnStop_Click(object sender, EventArgs e)
{
timer1.Stop();
}
}
}
解决方案
Hi,
Try this.
WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer(); wplayer.URL = "mp3 URL"; wplayer.controls.play();
Interop.WMPLib.dll You can download from the following url, and add dll reference to your project.
http://www.dllme.com/dll/download/22969/Interop.WMPLib.dll[]
Here is good example with sample code
Use a timer to create a simple alarm application[^]
这篇关于如何使用c#制作电脑报警的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文