c#定时提示器代码

 C#原代码

 最佳答案
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Media;
using System.Diagnostics;

namespace WindowsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)//添加时间选项
        {
          
            for (int i = 0; i < 24; i++)
            {
                this.comboBox1.Items.Add(i);
            }
            for (int j = 0; j < 60; j++)
            {
                this.comboBox2.Items.Add(j);
                this.comboBox3.Items.Add(j);
            }
            this.comboBox1.SelectedItem = 12;
            this.comboBox2.SelectedItem = 0;
            this.comboBox3.SelectedItem = 0;
        }

        private void button1_Click(object sender, EventArgs e)//定时器的设置
        {
                timer1.Enabled = true;
        }
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            this.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        Form2 f2 = new Form2();
        private void timer1_Tick(object sender, EventArgs e)//设置确定的时间
        {
            DateTime dt = Convert.ToDateTime(this.dateTimePicker1.Text.ToString() + this.comboBox1.SelectedItem.ToString() + ":" + this.comboBox2.SelectedItem.ToString() + ":" + this.comboBox3.SelectedItem.ToString());
            if (System.DateTime.Now.ToLocalTime().ToString().Equals(Convert.ToString(dt)))
            {
               
                this.timer1.Enabled = false;
                if (f2.s != "")
                {
                    string s = f2.paths;
                    if (s.Contains(".wav") || s.Contains(".mp3"))
                    {
                        f2.play(s);
                    }
                    else if (s.Contains(".exe"))
                    {
                        Process hxj = new Process();
                        hxj.StartInfo.FileName = s;
                        hxj.StartInfo.UseShellExecute = false;
                        hxj.StartInfo.RedirectStandardInput = true;
                        hxj.StartInfo.RedirectStandardOutput = true;
                        hxj.StartInfo.RedirectStandardError = false;
                        hxj.StartInfo.CreateNoWindow = true;
                        hxj.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                        try
                        {
                            hxj.Start();
                            hxj.WaitForExit();
                            hxj.Close();
                        }
                        catch (Exception er)
                        {
                            s = er.Message;
                        }
                    }
                    MessageBox.Show(f2.s, "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);//添加执行事件
                    f2.s = "";                  
                }

            }
        }

        private void 退出TToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult dt = MessageBox.Show("是否要退出本程序?","提示",MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (dt == DialogResult.No)
            {
                e.Cancel = true;
            }
            else
            {
                f2.Close();
                e.Cancel = false;
            }
        }

        private void 提示信息HToolStripMenuItem_Click(object sender, EventArgs e)
        {
            f2.Show();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            this.textBox1.Text = Convert.ToString(System.DateTime.Now.ToLocalTime());
        }

        private void Form1_SizeChanged(object sender, EventArgs e)
        {
            this.ShowInTaskbar = false;
            this.notifyIcon1.Visible = true;
        }

        private void notifyIcon1_Click(object sender, EventArgs e)
        {
            this.Visible = true;
            this.WindowState = FormWindowState.Normal;
            this.notifyIcon1.Visible = false;
        }

 

 

    }
}

 

 

 

*************************form2.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Media;
using System.IO;
using System.Diagnostics;

namespace WindowsApplication3
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        public string s;
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.richTextBox1.Text.Equals(""))
            {
               DialogResult ds= MessageBox.Show("确定不填写提示信息","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
               if (ds == DialogResult.Yes)
               {            
                   this.Close();
               }
            }
            else
            {
                s = this.richTextBox1.Text;
                MessageBox.Show("你已经成功的设定了提示信息", "提示");
                this.Hide();
                //this.Close();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Clear();
        }

        private void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {
            //DialogResult dt = MessageBox.Show("是否要退出吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            //if (dt == DialogResult.No)
            //{
            //    e.Cancel = true;
            //}

        }
        public string paths;
        private void 音乐YToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string path;
            this.openFileDialog1.ShowDialog();
            this.openFileDialog1.Filter = "wav|*.wav";
            path=this.openFileDialog1.FileName;
            FileInfo f = new FileInfo(path);
             paths = f.FullName;
            this.视频VToolStripMenuItem.Enabled = false;
            this.执行文件EToolStripMenuItem.Enabled = false;
        }

        private void 视频VToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.openFileDialog1.ShowDialog();
            this.openFileDialog1.Filter = "avi|*.avi | mp4|*.mp4";
            this.音乐YToolStripMenuItem.Enabled = false;
            this.执行文件EToolStripMenuItem.Enabled = false;
        }
        public void play(string paths)
        {
            if (System.IO.File.Exists(paths))
            {
                SoundPlayer s = new SoundPlayer(paths);
                s.Play();
            }

        }

        private void 执行文件EToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string path;
            this.openFileDialog1.ShowDialog();
            this.openFileDialog1.Filter = "exe|*.exe";                           
            path = this.openFileDialog1.FileName;
            FileInfo f = new FileInfo(path);
            paths = f.FullName;
            this.视频VToolStripMenuItem.Enabled = false;
            this.音乐YToolStripMenuItem.Enabled = false;

        }
        private  void 用酷狗方式KToolStripMenuItem_Click(object sender, EventArgs e)
        {
            paths = @"C:/Program Files/KuGou/KuGou2008/KuGoo.exe";
            this.视频VToolStripMenuItem.Enabled = false;
            this.音乐YToolStripMenuItem.Enabled = false;
            this.执行文件EToolStripMenuItem.Enabled = false;
            this.用暴风影音BToolStripMenuItem.Enabled = false;
           

        }

        private void 用暴风影音BToolStripMenuItem_Click(object sender, EventArgs e)
        {
            paths = @"C:/Program Files/StormII/Storm.exe";
            this.视频VToolStripMenuItem.Enabled = false;
            this.音乐YToolStripMenuItem.Enabled = false;
            this.执行文件EToolStripMenuItem.Enabled = false;
            this.用酷狗方式KToolStripMenuItem.Enabled = false;
        }
    }
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值