C
Curious
Hi All,
I saw a sample code and I think it makes life more complicated with
delegate and event handler stuff. Please correct me if I were wrong.
I have a method defined as below:
private void POToolBar_ButtonClick (object sender,
System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch (e.Button.Tag.ToString())
{
case "Refresh":
DataRefreshMenuItem.PerformClick(); // This calls
the delegate
break;
case "Add":
NewOrderItemButton.PerformClick();
break;
case "Save":
SaveOrderButton.PerformClick();
break;
}
}
Then in the debugger, when executing
"DataRefreshMenuItem.PerformClick();", it goes to
private void DataRefreshMenuItem_Click(object sender,
System.EventArgs e)
{
//blah, blah, blah
}
Obviously, this is because DataRefreshMenuItem.PerformClick is defined
as this.DataRefreshMenuItem_Click in the following code:
this.DataRefreshMenuItem.Click += new
System.EventHandler(this.DataRefreshMenuItem_Click);
Can anyone please tell me why call an intermediate method,
"DataRefreshMenuItem.Click" instead of calling
DataRefreshMenuItem_Click?
I could accomplish the same thing by defining a method,
DataRefreshMenuItem_Click, and call this exact method from
POToolBar_ButtonClick.
Thanks!
I saw a sample code and I think it makes life more complicated with
delegate and event handler stuff. Please correct me if I were wrong.
I have a method defined as below:
private void POToolBar_ButtonClick (object sender,
System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch (e.Button.Tag.ToString())
{
case "Refresh":
DataRefreshMenuItem.PerformClick(); // This calls
the delegate
break;
case "Add":
NewOrderItemButton.PerformClick();
break;
case "Save":
SaveOrderButton.PerformClick();
break;
}
}
Then in the debugger, when executing
"DataRefreshMenuItem.PerformClick();", it goes to
private void DataRefreshMenuItem_Click(object sender,
System.EventArgs e)
{
//blah, blah, blah
}
Obviously, this is because DataRefreshMenuItem.PerformClick is defined
as this.DataRefreshMenuItem_Click in the following code:
this.DataRefreshMenuItem.Click += new
System.EventHandler(this.DataRefreshMenuItem_Click);
Can anyone please tell me why call an intermediate method,
"DataRefreshMenuItem.Click" instead of calling
DataRefreshMenuItem_Click?
I could accomplish the same thing by defining a method,
DataRefreshMenuItem_Click, and call this exact method from
POToolBar_ButtonClick.
Thanks!