如何使用c#创建pc报警 [英] How to create a pc alarm using c#

查看:50
本文介绍了如何使用c#创建pc报警的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想报警,我写了一些关于它的代码。但我无法添加音乐。

请帮帮我。

Hi, I want to make ana alarm and I wrote some code about it. But I can't add a music.
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.Threading.Tasks;
using System.Windows.Forms;
using System.Media;
using System.Globalization;
using System.Diagnostics;

namespace ALARM
{
    public partial class Alarm : Form
    {
        public Alarm()
        {
            InitializeComponent();
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            bool isAlarmOk = true;

            while (isAlarmOk)
            {
                string dt = DateTime.Now.ToShortTimeString();
                
                if (string.Compare(dt,txtTime.Text) == 0)
                {
                    isAlarmOk = false;
                    SoundPlayer sp = new SoundPlayer();
                    sp.SoundLocation = @"C:\Users\Rahsan-PC\Documents\Visual Studio 2012\Projects\ALARM\ALARM\bin\Debug\sound\ding.wav";
                    sp.Load();
                    sp.PlaySync();
                    break;
                }
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            timer1.Stop();
        }

        private void Alarm_Load(object sender, EventArgs e)
        {
            txtDay.Text = DateTime.Now.ToShortDateString();
            txtTime.Text = DateTime.Now.ToShortTimeString();
        }
    }
}

推荐答案





使用计时器创建一个简单的报警应用程序 [ ^ ]



本文可能对您有所帮助
Hi,

Use a timer to create a simple alarm application[^]

This article may very helpful for you


这篇关于如何使用c#创建pc报警的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆