如何确定日期时间选择器值是否已更改? [英] How to find out if datetime picker value is changed or not?

查看:131
本文介绍了如何确定日期时间选择器值是否已更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两件事。一个是ValueChanged,另一个是TextChanged



如果价值改变了,那么我可以做一些我真正需要的事情



但是下面两个条件得到同样的错误



怎么知道价值是否改变了?



There are two events. One is ValueChanged and another one is TextChanged

If value is changed then I can do something that is my need actually

But following two conditions getting same error

How to know the value is changed or not?

if (datetimepicker.ValueChanged == true)
       {
          strMonthCode = "JAN";
        }
      else if (datetimepicker.TextChanged == true)
        {
          strMonthCode = "FEB";
        }





在这两种情况下我都收到错误



In both cases I am getting an error

推荐答案

你不能那样使用它们。他们是事件 - 而不是财产。您需要添加一个事件处理程序。类似于:



You can''t use them like that. They''re events - not properties. You need to add an eventhandler. Something like:

public partial class Form1 : Form
{
    private bool dateChanged = false;

    private void Form1_Load(object sender, EventArgs e)
    {
        dateTimePicker1.ValueChanged += new System.EventHandler(dateTimePicker1_ValueChanged);
    }

    private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
    {
        dateChanged = true;
        //Here you can do stuff that needs to be done when the value changes
    }

    private void button1_Click(object sender, EventArgs e)
    {
        //Example: Here you can check if the value has changed since you opened the form:
        if (dateChanged)
        {
            //The date has been changed - do what I need to do
        }
    }
}


这篇关于如何确定日期时间选择器值是否已更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆