[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How do I pass parameters/objects to an Eventhandler?

Posted on 2008-10-11
2
Medium Priority
?
2,956 Views
Last Modified: 2013-12-17
I am confused as to how I have to pass parameters/objects to an Eventhandler?

I have:

linklabel.click  += new EventHandler(hwIDForm);
linklabel is a LinkLabel type object.

which points to a method with signature:

private static void hwIDForm(object sender, EventArgs e){}

I derived a new class from EventArgs and added to it the ability to return the objects I want to pass, but I am at a loss as to how I pass it to hwIDForm when I define the event, there are no overloads to specify.
Any help is appreciated. MSDN
0
Comment
Question by:Matt_Du
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 22695539
in this case, you can't. the click event has a defined argument class. What you you want to pass? you can put some info at linklabel's Tag property, so you can retrieve as:

object info = (sender as Control).Tag;
0
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 500 total points
ID: 22697370
As already mentioned by Jaime Olivares you cannot use the click event. In order to use your own event you have to take the following steps

How to Raise an Event
At a minimum, you must do three things to raise an event:

Create a delegate:
// C#
public delegate void MyEventHandler(object sender, EventArgs e);

Create an event member:
// C#
public event MyEventHandler MyEvent;

Invoke the delegate within a method when you need to raise the event, as the following code demonstrates:
// C#
MyEventHandler handler = MyEvent;
EventArgs e = new EventArgs();
if (handler != null)
{
    // Invokes the delegates.
    handler(this, e);
}
// Note that C# checks to determine whether handler is null.

Additionally, you can derive a custom class from EventArgs if you need to pass information to the event handler.

0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question