面向对象winform版小闹钟

本文介绍了一个基于WinForm的简易闹钟应用程序开发过程。该应用可通过用户设置的时间播放背景音乐,并通过重写DLL方法实现了闹钟延迟十秒的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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; }
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值