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 err开发者_运维百科ors. 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?
It's best to call the Event handler with the default parameters:
AlarmListBox_Click(self, EventArgs.Empty);
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.
You are not passing the parameters of the method AlarmListBox_Click
Try this
AlarmListBox_Click(nil, nil);
精彩评论