469,271 Members | 954 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

How to identify event sender......

Hi all,
I have problem........ I have array of buttons and I want to call one
common event service. But I need to know the index of clicked button -- how
can I do that?

thanks
jakub
Nov 15 '05 #1
3 23258
Ok, I knew there was an easier (less code) way to do this...

Basically create your handler function like so:

private void ButtonHandler(object sender, System.EventArgs e) {

MessageBox.Show(sender.ToString());

}

Then, For each button you can select the Events in the Properties box and
change the Click event to point to your ButtonHandler function.
---
John Wiese
---
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"John Wiese [MS]" <jw****@online.microsoft.com> wrote in message
news:#e**************@TK2MSFTNGP11.phx.gbl...
Jakub,

You could write your own function that takes the same parameter (sender, e) as the btn_click funcitons, then in your btn_click simply call your function passing along the input parameters you got. This would allow your handler
function to use sender.ToString() to determine which button was clicked.

John Wiese

--
This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Jakub Otahal" <jo*****@ftvs.cuni.cz> wrote in message
news:ue**************@TK2MSFTNGP11.phx.gbl...
Hi all,
I have problem........ I have array of buttons and I want to call one
common event service. But I need to know the index of clicked button --

how
can I do that?

thanks
jakub


Nov 15 '05 #2
Hi,

You can use the sender parameter of the handler to see what control sent
the event, if you have your controls in an array it would be something like:

protected void handler( object o, EventArgs e ){

int index = 0;
foreach( Control control in controlArray)
{
if ( sender == control )
break;
index++;
}
}

hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Jakub Otahal" <jo*****@ftvs.cuni.cz> wrote in message
news:ue**************@TK2MSFTNGP11.phx.gbl...
Hi all,
I have problem........ I have array of buttons and I want to call one
common event service. But I need to know the index of clicked button -- how can I do that?

thanks
jakub

Nov 15 '05 #3
"Jakub Otahal" <jo*****@ftvs.cuni.cz> wrote in message
news:ue**************@TK2MSFTNGP11.phx.gbl...
Hi all,
I have problem........ I have array of buttons and I want to call one
common event service. But I need to know the index of clicked button -- how can I do that?


The button itself is being passed as "sender," but if you really need it's
index you can save it in buttons "Tag" property.
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by Alphonse Giambrone | last post: by
5 posts views Thread by Joey G | last post: by
7 posts views Thread by Grahmmer | last post: by
13 posts views Thread by Charles Law | last post: by
4 posts views Thread by Reny J Joseph Thuthikattu | last post: by
1 post views Thread by Jim McGivney | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.