how to access Custom EventArgs class in Button click event?

后端 未结 3 771
余生分开走
余生分开走 2021-01-27 03:13

As a follow up to: access values within custom eventargs class

How do I access public variables within custom Eventargs class, using button click or any other method?

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-27 03:29

    When the button click event is raised, it's creating the EventArgs that gets passed into "e". That object was not created by you, but rather by the framework itself, and is of type EventArgs. This prevents you from being able to cast it to a different type.

    If you want to have an event that raises TraderEventArgs, you need to create an event, preferably of type EventHandler, and raise this event somewhere that is in your control. This allows you to generate the class of the correct type, then handle it (in a separate event handler) directly.

提交回复
热议问题