| 1234567891011121314151617181920212223242526272829303132333435363738394041 | using System;using System.Collections.Generic;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;namespace YG.Device{    public class LableLib    {        private static LableLib lableHandle = new LableLib();        public static LableLib Instance { get { return lableHandle; } }        /// <summary>        ///         /// </summary>        /// <param name="lb"></param>        /// <param name="sleeptime">保持绿灯多少毫秒,-1是长亮</param>        public void LableColorChange(System.Windows.Forms.Label lb, int sleeptime)        {            lb.BeginInvoke(new Action(() =>            {                lb.AutoSize = false;                lb.Text = "";                lb.Size = new Size(23, 23);                lb.BackColor = Color.Green;                               Task.Factory.StartNew(() =>                {                    if (sleeptime > 0)                    {                        System.Threading.Thread.Sleep(sleeptime);                        lb.BackColor = Color.Red;                    }                });            }));        }    }}
 |