Click here to Skip to main content
15,901,426 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to do this in C#? Pin
Christian Graus28-Oct-04 15:01
protectorChristian Graus28-Oct-04 15:01 
GeneralRe: adding parameter to eventhandler Pin
sreejith ss nair28-Oct-04 2:18
sreejith ss nair28-Oct-04 2:18 
GeneralRe: adding parameter to eventhandler Pin
Stefan Troschuetz28-Oct-04 2:44
Stefan Troschuetz28-Oct-04 2:44 
GeneralRe: adding parameter to eventhandler Pin
Nick Parker28-Oct-04 3:35
protectorNick Parker28-Oct-04 3:35 
GeneralRe: adding parameter to eventhandler Pin
Member 147654828-Oct-04 3:51
Member 147654828-Oct-04 3:51 
GeneralRe: adding parameter to eventhandler Pin
Nick Parker28-Oct-04 5:01
protectorNick Parker28-Oct-04 5:01 
GeneralRe: adding parameter to eventhandler Pin
Anonymous28-Oct-04 6:08
Anonymous28-Oct-04 6:08 
GeneralRe: adding parameter to eventhandler Pin
Heath Stewart28-Oct-04 14:52
protectorHeath Stewart28-Oct-04 14:52 
You can't add a parameter. Event handlers (callbacks) must match the signature exactly for the events (multi-cast delegates).

For most events in the .NET BCL, however, you already have a way to do this. What do you think the sender (first parameter) is? It's the object that fired the event. So cast this to a LinkButton and then you can determine which LinkButton fired the event easily using a name or ID, or use referential equality to determine which LinkButton was clicked, or don't even care and just print what a LinkButton would define. Examples of all three are below:
linkButton1.Click += new EventHandler(OpenMtnStndards);
linkButton2.Click += new EventHandler(OpenMtnStndards);
linkButton3.Click += new EventHandler(OpenMtnStndards);
 
// ...
 
private void OpenMtnStandards(object sender, EventArgs e)
{
  LinkButton lb = sender as LinkButton;
  if (lb != null)
  {
    // Just print the link text. It will be correct for whichever LinkButton
    // was clicked.
    Trace.Warn(lb.Text);
 
    // Identity which LinkButton was clicked by it's ID.
    switch (lb.ID)
    {
      case "lb1":
        Trace.Warn("You clicked LinkButton 1");
        break;
      case "lb2":
        Trace.Warn("You clicked LinkButton 2");
        break;
      case "lb3":
        Trace.Warn("You clicked LinkButton 3");
        break;
    }
  }
 
  // Using referential equality
  if (sender == linkButton1)
    Trace.Warn("You clicked LinkButton number 1");
  else if (sender == linkButton2)
    Trace.Warn("You clicked LinkButton number 2");
  else if (sender == linkButton3)
    Trace.Warn("You clicked LinkButton number 3");
}
If you read the documentation for the EventHandler class - the type of the Click event, it does tell you want the sender parameter is (you can declare it as any name you want, however).

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
Generaladding parameter to eventhandler Pin
Member 147654828-Oct-04 1:57
Member 147654828-Oct-04 1:57 
GeneralModifying Numeric Pad Decimal Key Behavior Pin
Skynyrd28-Oct-04 1:34
Skynyrd28-Oct-04 1:34 
GeneralRe: Modifying Numeric Pad Decimal Key Behavior Pin
Anonymous29-Oct-04 6:37
Anonymous29-Oct-04 6:37 
QuestionUPnP anyone? Pin
Assaad Chalhoub28-Oct-04 1:25
Assaad Chalhoub28-Oct-04 1:25 
GeneralHelp - Dual Display Pin
Craig G Fraser28-Oct-04 0:52
Craig G Fraser28-Oct-04 0:52 
GeneralRe: Help - Dual Display Pin
Heath Stewart28-Oct-04 6:40
protectorHeath Stewart28-Oct-04 6:40 
GeneralRe: Help - Dual Display Pin
Craig G Fraser28-Oct-04 21:28
Craig G Fraser28-Oct-04 21:28 
GeneralRe: Help - Dual Display Pin
Heath Stewart29-Oct-04 5:42
protectorHeath Stewart29-Oct-04 5:42 
Generalinstalling a C# application on a customer's machine Pin
steve_rm28-Oct-04 0:32
steve_rm28-Oct-04 0:32 
GeneralRe: installing a C# application on a customer's machine Pin
sreejith ss nair28-Oct-04 2:02
sreejith ss nair28-Oct-04 2:02 
GeneralRe: installing a C# application on a customer's machine Pin
steve_rm28-Oct-04 4:03
steve_rm28-Oct-04 4:03 
GeneralRe: installing a C# application on a customer's machine Pin
sreejith ss nair28-Oct-04 4:11
sreejith ss nair28-Oct-04 4:11 
GeneralRe: installing a C# application on a customer's machine Pin
Dave Kreskowiak28-Oct-04 4:51
mveDave Kreskowiak28-Oct-04 4:51 
GeneralRe: installing a C# application on a customer's machine Pin
Heath Stewart28-Oct-04 6:50
protectorHeath Stewart28-Oct-04 6:50 
Generalp/invoke SendMessage(Hwnd,msg, wparam, lparam) question Pin
ting66827-Oct-04 23:58
ting66827-Oct-04 23:58 
GeneralRe: p/invoke SendMessage(Hwnd,msg, wparam, lparam) question Pin
yoaz28-Oct-04 0:53
yoaz28-Oct-04 0:53 
GeneralCalling a method from an EXE in C# Pin
skrishnasarma27-Oct-04 23:19
skrishnasarma27-Oct-04 23:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.