Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Sure thing. think of an event as the notification that occurs when something completes in the system that your code didn’t directly call. In C# it's really easy to get code to run when an event "fires"</p> <p>For example when a user presses a button an event will be raised or when a background network operation completes. In C# you use the += semantics to attach to the event that will be “signaled” when the event fires.</p> <p>I made you a simple C# winforms program – in it I added a button using the Visual Studio “Designer” (I just dragged a button from the Toolbox to the Window).</p> <p>You’ll see the line “button1.Click” – in this case I want to do something when the “Click” event is raised. </p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace events { public partial class Form1 : Form { public Form1() { InitializeComponent(); button1.Click += new EventHandler(button1_Click); } void button1_Click(object sender, EventArgs e) { MessageBox.Show("Hi!"); } } } </code></pre> <p>You’ll also see other kinds of events in practice for example:</p> <ul> <li>Network operation has completed (<a href="http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx" rel="nofollow noreferrer">WebClient.DownloadFileCompleted</a>) </li> <li>User Interfaces (resizing windows for example)</li> <li><a href="http://msdn.microsoft.com/en-us/library/system.timers.timer(VS.71).aspx" rel="nofollow noreferrer">Timers</a> (set off the timer in 10 minutes) </li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload