1

我正在尝试从同一个窗口窗体文件的另一个方法中调用单击事件。它对我不起作用。

例如:

  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 等。

我得到的一些错误:

  1. 没有参数为 0 的重载方法“AlarmListBox_Click”。
  2. 无法访问基础事件字段

那么,如何在同一个窗体窗体中触发事件呢?

4

2 回答 2

1

最好使用默认参数调用事件处理程序:

AlarmListBox_Click(self, EventArgs.Empty);

通过将 self 传递给方法,您可以定义调用的来源不是 AlarmListBox,而是您的表单。您还可以传入自定义 EventArgs,声明事件不是因为单击 AlarmListBox 而不是来自您的代码而引发的。

于 2011-08-31T05:29:03.177 回答
0

您没有传递方法的参数AlarmListBox_Click

试试这个

AlarmListBox_Click(nil, nil);
于 2011-08-30T19:37:09.093 回答