代码之家  ›  专栏  ›  技术社区  ›  JYelton Melchior Blausand

如何通过编程在自定义控件中引发现有事件?

  •  0
  • JYelton Melchior Blausand  · 技术社区  · 14 年前

    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 事件。

    如果控件填充并且用户按下删除,则它清除并将其值设置为NULL,但 更改值 事件 不会触发。

    在控件中 OnKeyDown method, I would like to include some code that raises the 更改值 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?

    2 回复  |  直到 14 年前
        1
  •  3
  •   Quartermeister    14 年前

    DateTimePicker.OnValueChanged 将引发ValueChanged事件。

        2
  •  1
  •   Femaref    14 年前

    您必须呼叫/覆盖 DateTimePicker.OnValueChanged() . 此方法调用事件,因此可以通过此方法实现代码。