about events

  • Thread starter Thread starter e-mid
  • Start date Start date
E

e-mid

i registered two events with a button.
when i press it , how can i know which is fired first?
or is there a way to make one of them get fired before the other one?

in fact i made a experiment about it :

i put message boxes in the events, when i press button only one event is
fired and other is never. why does that happens?
 
hi,
based on this sample, events are fired according
to the sequence of subscription.

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

public class WindowsForm : System.Windows.Forms.Form
{
private Button btn = new Button();

public static void Main()
{
Application.Run(new WindowsForm());
}

public WindowsForm()
{
btn.Click += new EventHandler(btnClick1);
btn.Click += new EventHandler(btnClick3);

btn.Click += new EventHandler(btnClick2);
btn.Text = "Click";
this.Controls.Add(btn);
}

private void btnClick1(object sender, EventArgs e)
{
MessageBox.Show("1");
}

private void btnClick2(object sender, EventArgs e)
{
MessageBox.Show("2");
}

private void btnClick3(object sender, EventArgs e)
{
MessageBox.Show("3");
}

}


HTH,
 
Back
Top