• 大小: 2.31MB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2023-09-11
  • 语言: 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.Threading;
using System.Media;
/*本案例讲解说明 闹钟小程序
 * 运用重要的知识点有四个:(练习使用)
 * 
 * 1.多线程的开辟与关闭
 * 2.获取系统时间
 * 3.播放音乐
 * 4.自动加载comboBox 的项
 * 
 * 若是有问题可联系作者
 * 作者: 不和傻瓜说话  QQ:641651345   上传源码时请保留以上信息 谢谢
 * **/
namespace WindowsApplicationtime
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Thread t;//线程
        public static string time11;//闹钟1
        public static string time12; //闹钟2
        public static string time13;//闹钟3
        private void timer1_Tick(object sender EventArgs e)//定义定时器
        {
            time();
        }

        public void time()
        {
            //DateTime.Now.Date.ToString() 当前日期
            string n = DateTime.Now.Year.ToString() + “年“ + DateTime.Now.Month.ToString() + “月“ + DateTime.Now.Day.ToString() + “日“;

            string s = DateTime.Now.Hour.ToString() + “时“;
            string f = DateTime.Now.Minute.ToString() + “分“;
            string m = DateTime.Now.Second.ToString() + “秒“;

            label2.Text = “今天是:“ + n + s + f + m;
            label11.Text = s + f + m;
            string timer11 = comboBox1.Text + “时“ + comboBox2.Text + “分“ + “0秒“;
            string timer12 = comboBox4.Text + “时“ + comboBox3.Text + “分“ + “0秒“;
            string timer13 = comboBox6.Text + “时“ + comboBox5.Text + “分“ + “0秒“;
            label12.Text = timer11;
            if (timer11.Equals(s + f + m))
            {
                t = new Thread(new ThreadStart(ThreadP));
                t.Start();//开启线程

            }else if(timer12.Equals(s + f + m))
            {
                t = new Thread(new ThreadStart(ThreadP));
                t.Start();

            }
            else if (timer13.Equals(s + f + m))
            {
                t = new Thread(new ThreadStart(ThreadP));
                t.Start();

            }
        }
        public void ThreadP() 
        {
            //上面是播放音乐
            //System.IO.FileStream fr = new System.IO.FileStream(“1.wav“ System.IO.FileMode.Open System.IO.FileAccess.Read System.IO.FileShare.ReadWrite);
            //System.Media.SoundPlayer pr = new System.Media.SoundPlayer(fr);
            //pr.Play();



            //播放系统的声音
            Console.Beep();
            Thread.Sleep(2000);
            t.Abort();//关闭系统 
        }
        private void Form1_Load(object sender EventArgs e)
        {
            timer1.Enabled = true;//启用定时器
            timer1.Start();//开启定时器
            for (int i = 0; i < 24;i++ )
            {
                comboBox1.Items.Add(i);//自动添加comboBox的值
                comboBox4.Items.Add(i);
                comboBox6.Items.Add(i);


            }
            for (int i = 0; i < 60; i++)
            {

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        955  2011-11-28 21:42  WindowsApplicationtime\WindowsApplicationtime.sln

    ..A..H.     13312  2011-11-29 21:42  WindowsApplicationtime\WindowsApplicationtime.suo

     文件       3305  2011-11-28 22:05  WindowsApplicationtime\WindowsApplicationtime\WindowsApplicationtime.csproj

     文件        481  2011-11-28 21:42  WindowsApplicationtime\WindowsApplicationtime\Program.cs

     文件        373  2011-11-29 21:42  WindowsApplicationtime\WindowsApplicationtime\obj\WindowsApplicationtime.csproj.FileList.txt

     文件        180  2011-11-29 21:42  WindowsApplicationtime\WindowsApplicationtime\obj\Debug\WindowsApplicationtime.Form1.resources

     文件        180  2011-11-28 22:05  WindowsApplicationtime\WindowsApplicationtime\obj\Debug\WindowsApplicationtime.Properties.Resources.resources

     文件      24576  2011-11-29 21:42  WindowsApplicationtime\WindowsApplicationtime\obj\Debug\WindowsApplicationtime.exe

     文件      32256  2011-11-29 21:42  WindowsApplicationtime\WindowsApplicationtime\obj\Debug\WindowsApplicationtime.pdb

     文件        842  2011-11-29 21:42  WindowsApplicationtime\WindowsApplicationtime\obj\Debug\WindowsApplicationtime.csproj.GenerateResource.Cache

     文件       5632  2005-11-11 22:25  WindowsApplicationtime\WindowsApplicationtime\bin\Debug\WindowsApplicationtime.vshost.exe

     文件      24576  2011-11-29 21:42  WindowsApplicationtime\WindowsApplicationtime\bin\Debug\WindowsApplicationtime.exe

     文件      32256  2011-11-29 21:42  WindowsApplicationtime\WindowsApplicationtime\bin\Debug\WindowsApplicationtime.pdb

     文件    3209516  2011-11-28 23:36  WindowsApplicationtime\WindowsApplicationtime\bin\Debug\1.wav

     文件       5612  2011-11-28 21:42  WindowsApplicationtime\WindowsApplicationtime\Properties\Resources.resx

     文件        249  2011-11-28 21:42  WindowsApplicationtime\WindowsApplicationtime\Properties\Settings.settings

     文件       1202  2011-11-28 21:42  WindowsApplicationtime\WindowsApplicationtime\Properties\AssemblyInfo.cs

     文件       2898  2011-11-28 21:42  WindowsApplicationtime\WindowsApplicationtime\Properties\Resources.Designer.cs

     文件       1105  2011-11-28 21:42  WindowsApplicationtime\WindowsApplicationtime\Properties\Settings.Designer.cs

     文件       3521  2011-11-29 21:42  WindowsApplicationtime\WindowsApplicationtime\Form1.cs

     文件      12184  2011-11-29 21:42  WindowsApplicationtime\WindowsApplicationtime\Form1.Designer.cs

     文件       6008  2011-11-29 21:42  WindowsApplicationtime\WindowsApplicationtime\Form1.resx

     目录          0  2011-11-29 18:20  WindowsApplicationtime\WindowsApplicationtime\obj\Debug\TempPE

     目录          0  2011-11-29 18:20  WindowsApplicationtime\WindowsApplicationtime\obj\Debug

     目录          0  2011-11-29 18:20  WindowsApplicationtime\WindowsApplicationtime\bin\Debug

     目录          0  2011-11-29 18:20  WindowsApplicationtime\WindowsApplicationtime\obj

     目录          0  2011-11-29 18:20  WindowsApplicationtime\WindowsApplicationtime\bin

     目录          0  2011-11-29 18:20  WindowsApplicationtime\WindowsApplicationtime\Properties

     目录          0  2011-11-29 18:20  WindowsApplicationtime\WindowsApplicationtime

     目录          0  2011-11-29 18:20  WindowsApplicationtime

............此处省略3个文件信息

评论

共有 条评论

相关资源