qq_41934573 2020-08-18 16:42 采纳率: 0%
浏览 80

winform datagridview设置倒计时,双击某行,某行重新倒计时?

初始化开始倒计时,双击某行,某行重新倒计时,时间到时, 执行某个操作。求源码,求改下源码,谢谢

 public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        DateTime dtStart;

        List<DateTime> str = new List<DateTime>();

        private void btnStart_Click(object sender, EventArgs e)
        {
            AutoResetEvent autoEvent = new AutoResetEvent(false);          
            dtStart = DateTime.Now.AddMinutes(0.5);
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }



        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            return;
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            //使用List<>泛型集合填充DataGridView
            List<Student> students = new List<Student>();
            Student hat = new Student("Hathaway", "12", "Male","");
            Student peter = new Student("Peter", "14", "Male", "");
            //Student dell = new Student("Dell", "16", "Male", "");
            //Student anne = new Student("Anne", "19", "Female", "");
            System.Threading.Timer timerClose;
            students.Add(hat);
            students.Add(peter);
            //students.Add(dell);
            //students.Add(anne);
            this.dataGridView1.DataSource = students;
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (i == 0)
                {
                    DateTime dtStart1 = DateTime.Now.AddMinutes(0.5);
                    str.Add(dtStart1);
                }
                else {
                    DateTime dtStart2 = DateTime.Now.AddMinutes(0.5);
                    str.Add(dtStart2);
                }           
                timerClose = new System.Threading.Timer(new TimerCallback(timerCall), i, 1000, 1000);            
            }

        }
        private void timerCall(object obj)
        {
            int res = Convert.ToInt32(obj);
            TimeSpan ts = str[res] - DateTime.Now;
            this.dataGridView1.Rows[res].Cells[3].Value = string.Format("{0}分钟{1}秒", ts.Minutes, ts.Seconds);
            if (ts < TimeSpan.Zero)
            {
                this.dataGridView1.Rows[res].Cells[3].Value = "超时";

            }

        }
        private void CellDoubltimer(object obj)
        {
            DateTime Start = DateTime.Now.AddMinutes(0.5);//最后设置25
            int res = Convert.ToInt32(obj);
            TimeSpan ts = Start - DateTime.Now;
            this.dataGridView1.Rows[res].Cells[3].Value = string.Format("{0}分钟{1}秒", ts.Minutes, ts.Seconds);
            if (ts < TimeSpan.Zero)
            {
                  this.dataGridView1.Rows[res].Cells[3].Value = "超时";            
            }

        }


        public class Student {
            public string Name { get; set; }
            public string age { get; set; }
            public string xinbie { get; set; }
            public string times { get; set; }

            public Student(string v1, string v2, string v3,string v4)
            {
                this.Name = v1;
                this.age = v2;
                this.xinbie = v3;
                this.times = v4;
            }          
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            System.Threading.Timer timerClose;
            timerClose = new System.Threading.Timer(new TimerCallback(CellDoubltimer), e.RowIndex, 0, 1000);

        }
    }
  • 写回答

1条回答 默认 最新

  • dabocaiqq 2020-08-19 09:37
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 为什么apriori的运行时间会比fp growth的运行时间短呢
  • ¥15 帮我解决一下膳食平衡的线性规划模型的数据实例
  • ¥40 万年历缺少农历,需要和阳历同时显示
  • ¥250 雷电模拟器内存穿透、寻基址和特征码的教学
  • ¥200 比特币ord程序wallet_constructor.rs文件支持一次性铸造1000个代币,并将它们分配到40个UTXO上(每个UTXO上分配25个代币),并设置找零地址
  • ¥15 关于Java的学习问题
  • ¥15 如何使用chatgpt完成文本分类任务?
  • ¥15 已知速度v关于位置s的等式,怎么转化为已知位置求速度v的等式
  • ¥15 我有个餐饮系统,用wampserver把环境配置好了,但是后端的网页却进去,是为什么,能不能帮远程一下?
  • ¥15 R运行没有名称为"species"的插槽对于此对象类"SDMmodelCV"