在Delphi Prism中的同一窗口窗体内调用事件
我试图从同一窗口窗体文件的另一个方法中调用单击事件。对我来说这行不通。
例如:
theClass = partial class(System.Windows.Forms.Form)
method AlarmListBox_Click(sender: System.Object; e: System.EventArgs);
private
protected
public
method DoSomething;
end;
method theClass.DoSomething;
begin
self.AlarmListBox_Click; <<<this is where i want to call the click event
end;
无论我做什么,它都会不断引发编译器错误。我尝试了 AlarmListBox.Click、AlarmListBox.performClick 等。
我得到的一些错误:
- 没有重载方法“AlarmListBox_Click”,值为 0 参数。
- 无法访问底层事件字段
那么,如何在同一窗口窗体内触发事件呢?
I am trying to call a click event from within another a method from the same Window Form file. It just won't work form me.
For instance:
theClass = partial class(System.Windows.Forms.Form)
method AlarmListBox_Click(sender: System.Object; e: System.EventArgs);
private
protected
public
method DoSomething;
end;
method theClass.DoSomething;
begin
self.AlarmListBox_Click; <<<this is where i want to call the click event
end;
No matter what I do, it keeps raising compiler errors. I tried AlarmListBox.Click, AlarmListBox.performClick, etc.
Some of the errors I got:
- There is no overloaded method "AlarmListBox_Click" with 0
parameters. - Cannot access underlying event field
So, how do you fire an event within the same window Form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好使用默认参数调用事件处理程序:
通过将 self 传递到您定义的方法中,调用源不是 AlarmListBox 而是您的表单。您还可以传入自定义 EventArgs,表明该事件不是由于单击 AlarmListBox 而引发的,而是来自您的代码。
It's best to call the Event handler with the default parameters:
By passing self into the method you define that the source of the call was not the AlarmListBox but your form. You could also can pass in custom EventArgs that state that the Event was not raised because of a click on the AlarmListBox but from your code.
您没有传递方法
AlarmListBox_Click
的参数试试这个
You are not passing the parameters of the method
AlarmListBox_Click
Try this