Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Developers who know only C#, or only VB.Net, may not know that this is one of the larger differences between VB.NET and C#. </p> <p>I will <a href="http://visualstudiomagazine.com/Articles/2008/12/01/What-C-Devs-Should-Know-About-VB.aspx?Page=2" rel="nofollow noreferrer">shamelesssly copy</a> this nice explanation of VB events: VB uses a declarative syntax for attaching events. The <a href="http://msdn.microsoft.com/en-us/library/6k46st1y.aspx" rel="nofollow noreferrer">Handles</a> clause appears on the code that will handle the event. When appropriate, multiple methods can handle the same event, and multiple events can be handled by the same method. Use of the Handles clause relies on the <a href="http://msdn.microsoft.com/en-us/library/aty3352y.aspx" rel="nofollow noreferrer">WithEvents</a> modifier appearing on the declaration of the underlying variable such as a button. You can also attach property handlers using the <a href="http://msdn.microsoft.com/en-us/library/7taxzxka.aspx" rel="nofollow noreferrer">AddHandler</a> keyword, and remove them with RemoveHandler. For example</p> <pre><code>Friend WithEvents TextBox1 As System.Windows.Forms.TextBox Private Sub TextBox1_Leave(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles TextBox1.Leave 'Do Stuff ' End Sub </code></pre> <p>In C# you can't use the declarative syntax. You use += which is overloaded to act like the VB.Net AddHandler. Here's an example shamelessly stolen from <a href="https://stackoverflow.com/questions/1488573/how-to-raise-event-using-addhandler/1488623#1488623">tster's answer</a>:</p> <pre><code>public MyClass() { InitializeComponent(); textBox1.Leave += new EventHandler(testBox1_Leave); } void testBox1_Leave(object sender, EventArgs e) { //Do Stuff } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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