PC Review


Reply
Thread Tools Rate Thread

Array of buttons

 
 
saulij
Guest
Posts: n/a
 
      8th Oct 2008
I have an array of buttons. There is a common Click-method for these
buttons.
How can I find what button is clicked?

Sauli
 
Reply With Quote
 
 
 
 
Duggi
Guest
Posts: n/a
 
      8th Oct 2008
On Oct 8, 10:01*am, saulij <sau...@hotmail.com> wrote:
> I have an array of buttons. There is a common Click-method for these
> buttons.
> How can I find what button is clicked?
>
> Sauli


In the event handler, first arg would be "object sender". you can
identify the sender through this argument. (I believe so)

-Cnu
 
Reply With Quote
 
zacks@construction-imaging.com
Guest
Posts: n/a
 
      8th Oct 2008
On Oct 8, 1:09*pm, Duggi <DuggiSrinivasa...@gmail.com> wrote:
> On Oct 8, 10:01*am, saulij <sau...@hotmail.com> wrote:
>
> > I have an array of buttons. There is a common Click-method for these
> > buttons.
> > How can I find what button is clicked?

>
> > Sauli

>
> In the event handler, first arg would be "object sender". you can
> identify the sender through this argument. (I believe so)
>


I haven't tried this but it should work.

Private void Common_Click(Object sender, EventArgs e)
{
Button btn = (Button)sender;
switch (btn.Name)
{
case "btnButton1":
Do something for button1;
break;
case "btnButton2":
Do something for button2;
break;
etc ...
}
}
 
Reply With Quote
 
Duggi
Guest
Posts: n/a
 
      8th Oct 2008
On Oct 8, 10:42*am, za...@construction-imaging.com wrote:
> On Oct 8, 1:09*pm, Duggi <DuggiSrinivasa...@gmail.com> wrote:
>
> > On Oct 8, 10:01*am, saulij <sau...@hotmail.com> wrote:

>
> > > I have an array of buttons. There is a common Click-method for these
> > > buttons.
> > > How can I find what button is clicked?

>
> > > Sauli

>
> > In the event handler, first arg would be "object sender". you can
> > identify the sender through this argument. (I believe so)

>
> I haven't tried this but it should work.
>
> Private void Common_Click(Object sender, EventArgs e)
> {
> * * Button btn = (Button)sender;
> * * switch (btn.Name)
> * * {
> * * * * case "btnButton1":
> * * * * * * Do something for button1;
> * * * * * * break;
> * * * * case "btnButton2":
> * * * * * * Do something for button2;
> * * * * * * break;
> * * * * etc ...
> * * }
>
>
>
> }- Hide quoted text -
>
> - Show quoted text -


nice to see some code here. The same approach I was suggesting.

Saulij, Please let us know if it solves your issue.

-Cnu
 
Reply With Quote
 
Arthur Parker
Guest
Posts: n/a
 
      8th Oct 2008
Also, you could set the Tag property for each button and use that to identify
them.
 
Reply With Quote
 
saulij
Guest
Posts: n/a
 
      13th Oct 2008
Duggi kirjoitti:
> On Oct 8, 10:42 am, za...@construction-imaging.com wrote:
>> On Oct 8, 1:09 pm, Duggi <DuggiSrinivasa...@gmail.com> wrote:
>>
>>> On Oct 8, 10:01 am, saulij <sau...@hotmail.com> wrote:
>>>> I have an array of buttons. There is a common Click-method for these
>>>> buttons.
>>>> How can I find what button is clicked?
>>>> Sauli
>>> In the event handler, first arg would be "object sender". you can
>>> identify the sender through this argument. (I believe so)

>> I haven't tried this but it should work.
>>
>> Private void Common_Click(Object sender, EventArgs e)
>> {
>> Button btn = (Button)sender;
>> switch (btn.Name)
>> {
>> case "btnButton1":
>> Do something for button1;
>> break;
>> case "btnButton2":
>> Do something for button2;
>> break;
>> etc ...
>> }
>>
>>
>>
>> }- Hide quoted text -
>>
>> - Show quoted text -

>
> nice to see some code here. The same approach I was suggesting.
>
> Saulij, Please let us know if it solves your issue.
>
> -Cnu

This works fine, Thanks a lot

sauli
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array of Buttons WithEvents =?Utf-8?B?Q3JhaWc=?= Microsoft VB .NET 3 21st May 2006 10:23 PM
radio buttons (array) juli Microsoft C# .NET 6 1st Feb 2005 12:18 AM
C# to C++ problems: array of Buttons Picander Microsoft Dot NET 1 15th Jan 2005 08:47 PM
Array of Buttons Xarky Microsoft C# .NET 7 18th Sep 2004 06:06 PM
winforms buttons in an array ? n3crius Microsoft C# .NET 2 13th Mar 2004 08:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:31 PM.