I’m trying to learn raising and handling events in C#.
Here’s my simple example:
/////////////// creating a new BALL object ///
ballClass ball = new ballClass();
void button1_Click(object sender, EventArgs e)
{
// this should make the BALL object raise an event
ball.onHit();
label1.Text = "EVENT SEND";
}
// when event is fired, label text should change
void BallInPlayEvent(object sender, EventArgs e)
{
label2.Text = "EVENT FOUND!";
}
and the ball class:
class ballClass
{
public event EventHandler BallInPlay;
public void onHit()
{
this.BallInPlay ///// ??? how should i raise this event?
}
}
In the call I can’t really understand, how do I raise the event?
1 Answer