Jump to content
  • Advertisement
Sign in to follow this  
Winegums

Passing data to a c# event handler

This topic is 3717 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have an on click event handler that, when setup, I want to pass a certain object to the function (each button in the form corresponds to a certain piece of data that I'd like to modify). Should I make my own event handler, or is there a way to use the existing handler to do what I want?

Share this post


Link to post
Share on other sites
Advertisement
Make your own. Now depending on what you want to do. You can override the OnClick method. Or add a new handler to the OnClick event.

theTroll

Share this post


Link to post
Share on other sites
Ok I've created a new button class inherited from the System.Windows.Forms.Button class and I've overridden the OnClick event.

The problem is that I'm passing the button a thread, and the button then calls suspend or resume on the thread. but the thread passes data to another object, which it doesn't seem to carry a reference to if i pass it to the button.

I'm not especially well versed in c#, is there a more elegant way of doing this? My current thinking is either to inherit from the thread class, or make a wrapper class for each instance of a thread with buttons, progress bars etc for it.

Share this post


Link to post
Share on other sites
I'd go back to the built in button class and simply use the Tag property. Pretty much why it's there :)

Put your button-specific data in the Tag, and in your event handler just cast your 'sender' parameter to Button and use its Tag and you're good to go.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!