|
-
April 27th, 2004, 03:47 PM
#1
Delegate Question
In form based callbacks, where does the eventargs param come from?
I am implementing a dialog with eight browsing buttons that all share the same openfileDialog. I would like to have one callback function that serves all the browsing buttons and can identify who was clicked.
ie, a method like:
private void GenericBrowse_Click(object sender, System.EventArgs e)
{ ... // some code that only differs in who was clicked }
where all the browsers would subscribe like:
this.buttonBrowse1.Click += new System.EventHandler(this.GenericBrowse_Click);
In order to do this, i think i need to derive from System.EventArgs and give the derivative a "who was clicked" attribute. How do i do this and where is it created?
-
April 27th, 2004, 07:18 PM
#2
You want many buttons to share the same function, and you want to identify what button was clicked isn't it so?
You simply create the buttons with the windows forms designer (you can do that by code as well) and use the code you posted:
this.buttonBrowse1.Click += new System.EventHandler(this.GenericBrowse_Click);
in your GenericBrowser_Click you do that:
private void GenericBrowser_Click(object sender, EventArgs e)
{
if (sender.GetType() == Button)
{
Button current = (Button)sender;
MessageBox.Show(current.Name + " " + current.Tag);
}
}
that should do.. or did I misunderstand you question?
greetings UNI
-
April 28th, 2004, 06:31 AM
#3
That works great. Thanks!
-
April 28th, 2004, 05:24 PM
#4
I had exactly the same problem and asked here for help.. just a few days before you showed up ..
greetings UNI
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|