JYelton
JYelton

Reputation: 36512

How do I programatically raise an existing event within a custom control?

I have made a custom class by inheriting a DateTimePicker and made some methods that allow it to be blank/null.

If the control is blank and a user clicks on it, it populates with the current date. It also raises the ValueChanged event.

If the control is populated and a user presses delete, it clears and sets its value to null, but the ValueChanged event doesn't trigger.

In the control's OnKeyDown method, I would like to include some code that raises the ValueChanged event, but there doesn't seem to be a way to do that.

Do I need to override the base class event? Is there an applicable example?

Upvotes: 0

Views: 1606

Answers (2)

Quartermeister
Quartermeister

Reputation: 59129

DateTimePicker.OnValueChanged will raise the ValueChanged event.

Upvotes: 3

Femaref
Femaref

Reputation: 61427

You have to call/override DateTimePicker.OnValueChanged(). This method calls the event, so you can implement your code through this.

Upvotes: 1

Related Questions