Someone gave me this code that works great but I would really like to understand what is happening inside it, could somebody explain please? what is the meaning of each part of the code? The code is inside a custom control which has two labels inside a panel. Also I've seen some custom control events that use add/remove sytanx, what is that for? what is the difference with what is happening here?
Thanks in advance
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public event EventHandler MyCustomClickEvent;
protected virtual void OnMyCustomClickEvent(EventArgs e)
{
// Here, you use the "this" so it's your own control. You can also
// customize the EventArgs to pass something you'd like.
if (MyCustomClickEvent != null)
MyCustomClickEvent(this, e);
}
private void label1_Click(object sender, EventArgs e)
{
OnMyCustomClickEvent(EventArgs.Empty);
}
}