Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

事件

定义和触发事件;创建响应事件的侦听程序

事件是发生涉及对象的某些更改或操作时的通知广播。侦听程序定义在发生特定事件时执行的函数。类可以定义和触发事件。当代码访问对象属性时,MATLAB® 可以触发预定义的事件。

函数

events事件名称
notify通知侦听程序事件正在发生
addlistener创建绑定到事件源的事件侦听程序
listener创建未绑定到事件源的事件侦听程序
event.hasListener确定事件是否存在侦听程序

event.EventData事件数据的基类
event.ClassInstanceEventInstanceCreatedInstanceDestroyed 事件的事件数据
event.listener定义侦听程序对象的类
event.PropertyEvent属性事件的数据
event.proplistener定义属性事件的侦听程序对象

主题

事件和侦听程序

实现侦听程序

  • Listener Callback Syntax
    Specify listener callbacks using function handles.
  • Callback Execution
    Errors in listener callbacks do not prevent execution of other listeners. However, the order of listener execution is not defined.
  • Listener Lifecycle
    MATLAB manages the lifecycle of listeners. For greater control of listener lifecycle, construct listener objects using the listener method instead of addlistener.
  • Determine If Event Has Listeners
    You can determine if there are listeners defined for a specific event and event source.

属性侦听程序

事件和侦听程序的示例