Not possible as those events do not use EventArgs
sub classes.
Edit:
you could of course create a new StackTrace()
object and check the frames method name to see which event it is :)
質問
I have 2 events:
this.lblSettings.MouseEnter += new System.EventHandler(this.HookEvent);
this.lblSettings.MouseLeave += new System.EventHandler(this.HookEvent);
They call this one Method:
private void HookEvent(object sender, EventArgs e)
{
try
{
string method = System.Reflection.MethodBase.GetCurrentMethod().Name;
Label label;
if (sender is Label)
{
//Get the event. eg: MouseEnter, MouseLeave
label = (Label)sender;
label.BackColor = Color.FromArgb(30, 30, 30);
}
else if (sender is PictureBox)
{
PictureBox picBox;
picBox = (PictureBox)sender;
Control control = picBox.Parent;
if (control is Panel)
{
foreach (Control ctrl in control.Controls)
{
if (ctrl is Label)
{
label = (Label)ctrl;
label.BackColor = Color.FromArgb(30, 30, 30);
break;
}
}
}
}
}
catch (Exception ex)
{
throw;
}
}
In the LABEL part, where I have the comment: "//Get the event. eg: MouseEnter, Mouseleave",
I want to see if this is the MouseEnter or the MouseLeave event being executed, because I want to do different things for each event.
解決
Not possible as those events do not use EventArgs
sub classes.
Edit:
you could of course create a new StackTrace()
object and check the frames method name to see which event it is :)