c# event handler example
Example 1: how to create event in c#
class Counter
{
public event EventHandler ThresholdReached;
protected virtual void OnThresholdReached(EventArgs e)
{
EventHandler handler = ThresholdReached;
handler?.Invoke(this, e);
}
}
Example 2: C# events
public class YourEventReceiveEventArgs : EventArgs
{
public byte[] YourDataAsProperties { get; private set; }
public DateTime DateTime { get; private set; } = DateTime.UtcNow;
internal DataReceiveEventArgs(byte[] Data){ this.Data = Data; }
}
public class YourEventPublishingClass
{
public delegate void YourEventHandler(object Sender, DataReceiveEventArgs e);
public event YourEventHandler YourEvent;
protected void RaseEvent()
{
if(true)
handler?.Invoke(this, e);
}
}
private class YourSubscriberClass
{
private YourEventPublishingClass YourEventPublishingClassProperty;
public YourSubscriberClass(YourEventPublishingClass EventClassIn)
{
YourEventPublishingClassProperty = EventClassIn;
YourEventPublishingClassProperty.YourEvent += YourEventRecivedMethodEvent;
}
private void YourEventRecivedMethodEvent(object Sender, YourEventReceiveEventArgs e)
{
}
}
Example 3: c# event
private void panel1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
}
private void panel1_MouseEnter(object sender, System.EventArgs e)
private void panel1_MouseHover(object sender, System.EventArgs e)
private void panel1_MouseLeave(object sender, System.EventArgs e)
private void panel1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
private void panel1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
private void panel1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
private void clearButton_Click(object sender, System.EventArgs e)
0