C#下写的一个报警控件

来源:互联网 发布:快手网络主播排行榜 编辑:程序博客网 时间:2024/06/10 13:06
using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Data;using System.Linq;using System.Text;using System.Windows.Forms;using System.Media;namespace Sound{    public partial class Sound : UserControl    {        System.Media.SoundPlayer player = new SoundPlayer(Properties.Resources.ALARM8);        private bool hasSound;        private bool ring;        public bool Ring        {            get { return ring; }            set            {                ring = value;                if (ring)                {                    pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;                    pictureBox1.Image = Properties.Resources.Sound;                    player.Dispose();                    player = new SoundPlayer(Properties.Resources.ALARM8);                    player.LoadAsync();                    player.PlayLooping();                }                else                {                    pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;                    pictureBox1.Image = Properties.Resources.NoSound;                    player.Stop();                }                hasSound = value;            }        }        public Sound()        {            InitializeComponent();        }        private void pictureBox1_Click(object sender, EventArgs e)        {            if (ring)            {                if (!hasSound)                {                    pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;                    pictureBox1.Image = Properties.Resources.Sound;                    player.Dispose();                    player = new SoundPlayer(Properties.Resources.ALARM8);                    player.LoadAsync();                    player.PlayLooping();                    hasSound = true;                }                else                {                    hasSound = false;                    pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;                    pictureBox1.Image = Properties.Resources.CloseSound;                    player.Stop();                }            }        }    }}直接贴代码了


原创粉丝点击