views:

357

answers:

1

I noticed that C#'s DateTimePicker is changing the date automatically when I'm changing Month or Year. So what I did is to override the ValueChanged and it is only fired when the CloseUp event is raised.

The problem now is I need an event if the user actually selected date in the calendar or the user clicks outside of the control.

Can you help me with this? Thanks :)

A: 

In a derived class, the overriden OnValueChanged method works for me well.

public class MyDateTimePicker : DateTimePicker
{
    // ... some stuff

    protected override void OnValueChanged(EventArgs eventargs)
    {
        System.Diagnostics.Debug.Write("Clicked -  ");
        System.Diagnostics.Debug.WriteLine(this.Value);
        base.OnValueChanged(eventargs);
    }

    protected override void OnCloseUp(EventArgs eventargs)
    {
        System.Diagnostics.Debug.Write("Closed -  ");
        System.Diagnostics.Debug.WriteLine(this.Value);
        base.OnCloseUp(eventargs);
    }

    // some more stuff ...
}
Indoril Nerevar