zoukankan      html  css  js  c++  java
  • C#小闹钟 v2.0

    接上一篇,这次加了一个浏览本地wav文件的功能 界面稍稍做了点小改动

    程序代码

    View Code
    using System;
    using System.Windows.Forms;
    using System.Media;

    namespace alarmClock
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }
    SoundPlayer player
    = new SoundPlayer();

    private void Form1_Load(object sender, EventArgs e)
    {
    timer1.Start();
    //绑定到combobox
    for (int i = 0; i <= 23; i++)
    {
    cmbHour.Items.Add(i);
    }
    for (int j = 0; j < 60; j++)
    {
    cmbMinute.Items.Add(j);
    }
    //绑定铃声
    cmbRing.Items.Add("步步高音乐.wav");
    cmbRing.Items.Add(
    "背景音乐.wav");
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
    timer1.Interval
    = 1000;
    lblNow.Text
    = DateTime.Now.ToString();
    }

    private void btnPreview_Click(object sender, EventArgs e)
    {
    playJudge();
    }
    /// <summary>
    /// 判断播放本地还是系统自带的
    /// </summary>
    private void playJudge()
    {
    if (cmbRing.Text==""&&txtUpload.Text=="")
    {
    MessageBox.Show(
    "请选择系统铃声或本地铃声");
    return;
    }
    if (cmbRing.Text == "" || txtUpload.Text != "")
    {
    playSound(txtUpload.Text);
    }
    if (cmbRing.Text != "" || txtUpload.Text == "")
    {
    playSound(cmbRing.Text);
    }
    }
    /// <summary>
    /// 播放wav声音文件
    /// </summary>
    private void playSound(string path)
    {
    //用new出来的实例点SoundLocation指定想要播放的音乐名称
    player.SoundLocation = path;//(将播放音乐放在应用程序Debug目录下)
    player.Load();
    //音乐播放
    player.Play();
    }

    private void btnOpen_Click(object sender, EventArgs e)
    {
    if (cmbHour.Text==""&&cmbMinute.Text=="")
    {
    MessageBox.Show(
    "没有设置闹铃的时刻");
    return;
    }
    timer2.Start();
    }

    private void timer2_Tick(object sender, EventArgs e)
    {
    timer2.Interval
    = 1000;
    string h = cmbHour.Text;
    string m = cmbMinute.Text;
    string nowH =DateTime.Now.Hour.ToString();
    string nowM = DateTime.Now.Minute.ToString();
    if (h == nowH && m == nowM)
    {
    playJudge();
    //开启后停止线程
    timer2.Stop();
    }
    }

    private void btnStop_Click(object sender, EventArgs e)
    {
    timer2.Stop();
    player.Stop();
    }
    /// <summary>
    /// 浏览本地铃声
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button1_Click(object sender, EventArgs e)
    {
    //判断是否打开了"打开文件对话框"
    if (openFileDialog1.ShowDialog()==DialogResult.OK)
    {
    string file=openFileDialog1.FileName;
    if (file!=null)
    {
    //判断上传文件是否为wav铃声
    //D:\winformTest\alarmClcok\myClock\bin\Debug\步步高音乐.wav
    string fileExtend = file.Substring(file.LastIndexOf(".") + 1).ToString().ToLower();
    if (fileExtend!="wav")
    {
    MessageBox.Show(
    "请选择wav类型的文件");
    return;
    }
    txtUpload.Text
    = file;
    }
    }
    }
    }
    }
  • 相关阅读:
    Python 迭代器&生成器,装饰器,递归,算法基础:二分查找、二维数组转换,正则表达式,作业:计算器开发
    python--如何在线上环境优雅的修改配置文件?
    Python补充--Python内置函数清单
    python3--open函数
    内置函数--map,filter,reduce
    Python内置函数—bytearray
    python lambda表达式简单用法
    Python浅拷贝copy()与深拷贝deepcopy()区别
    点击复制
    eval(function(p,a,c,k,e,d){e=function(c)加解密
  • 原文地址:https://www.cnblogs.com/Jaylong/p/alarm.html
Copyright © 2011-2022 走看看