⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usercontrol1.cs

📁 用C#实现的一个闹钟控件.可以在开发c#程序中直接使用,移植能力良好
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace myclock
{
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
                    
        }
        private string[,] a1 = new string[10, 2];
        public bool ontim = true;
        public string message;
        public int aa=0;
        private void timer1_Tick(object sender, System.EventArgs e)
        {
            dateTimePicker2.Value  = DateTime.Now;
            if (ontim == false && aa < 10)
            {
                label4.Text = message;
                if (aa % 2 == 0)
                {
                    label4.BackColor = System.Drawing.Color.PowderBlue;
                }
                else
                    label4.BackColor = System.Drawing.Color.LightGreen;
                aa++;
            }
            else
            {
                label4.Text = "";
                aa = 0;
                label4.BackColor = System.Drawing.Color.PowderBlue;
                ontim = true;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {

            
            DateTime dt = this.dateTimePicker1.Value;

            if (dt < DateTime.Now)
            {
                MessageBox.Show("对不起,您不能设置一个小于当前时间的值!");
                dateTimePicker1.Value = DateTime.Now;
                return;
            }
            if (textBox1.Text == "")
            {
                MessageBox.Show("您必须设置一个提示信息!");
                return;
            }
            //将定时时间和提醒信息在LIST中显示出来
            if (textBox1.Text.Length != 0 && listBox1.Items.Count < 10)
            {
                listBox1.Items.Add(dateTimePicker1.Text.ToString() + "     |     " + textBox1.Text.ToString());
                textBox1.Text = "";
            }

            //将时间和提醒保存到一个二维数组中
            for (int j = 0; j < listBox1.Items.Count; j++)
            {
                a1[j, 0] = listBox1.Items[j].ToString().Substring(0, listBox1.Items[j].ToString().IndexOf('|') - 5);
                a1[j, 1] = listBox1.Items[j].ToString().Substring(listBox1.Items[j].ToString().IndexOf('|') + 5);
            }
            
            MessageBox.Show("设置完毕!");
            timer2.Enabled = true;
            textBox1.Text = "";
        }
        public void OnTime()
        {
            for (int i = 0; i < 10; i++)
            {
                if (a1[i, 0] == DateTime.Now.ToLongTimeString())
                {
                    timer2.Enabled = false;
                    message = a1[i, 1];
                    //MessageBox.Show(a1[i, 1]);
                    ontim = false;
                    a1[i, 0] = a1[i, 1] = null;
                }
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            
                for (int j = 0; j < listBox1.SelectedItems.Count; j++)
                {
                    listBox1.Items.Remove(listBox1.SelectedItems[j]);
                    j--;
                }
            
        }
        private void timer2_Tick(object sender, EventArgs e)
        {
            //触发定时事件
            OnTime();
        }

        private void UserControl1_Load(object sender, EventArgs e)
        {

        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {

        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -