Click here to Skip to main content
15,905,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I know to create buttons through coding but dnt know how to add different functionality to it. my code is :
C#
for(int i=0;i<3;i++)
{                       Button bz = new Button();
                         bz.Height = 50;
                         bz.Width = 50;
                         bz.ToolTip = fname1;
                         gg.Children.Add(bz);
} // gg is uniformGrid

it create 3 buttons bt now i want each of this should perform different task like if i click first button it should add two no.s and if i click other then it will do subtraction... And how to give name to each of these buttons..??

thanks in advance

pls dnt give msdn.microsoft links they dnt help much..
Posted

hi,

you can create anonymous function and associate click event with your all buttons.

you can decide what you want to do with different buttons.

or you can associate your function like

C#
btn.Click += new System.EventHandler(this.myFunction);


Hope this will help you,

Thanks
-Amit
 
Share this answer
 
Comments
mane0806 4-Jun-12 12:30pm    
i did that inside loop for each button, but no use because, when i click any button it calls last function created for last button; because it overwrite previous methods.
AmitGajjar 4-Jun-12 23:56pm    
can you show me the code for the event binding ?
C#
btnHeader.Click += delegate { Functin_name() }

In this way you can create an event.If i click on the button it will come to btnHeader.Click and execute the functions present inside the bracket .

Hope this will help you :)
 
Share this answer
 
Comments
mane0806 4-Jun-12 13:08pm    
i did that inside loop for each button, but no use because, when i click any button it calls last function created for last button; because it overwrite previous methods.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900