Solved

Buttons?

Posted on 2006-11-06
4
621 Views
Last Modified: 2008-02-01
You want to accomplish the following with a Button Control:

1.) Add the Button
2.) Add the Event Handler
3.) Trigger the event

Which would be the correct segment of code to accomplish these tasks?
Button b = new Button(new EventHandler(onButtonAction));
b.clicked = True;
 
 
--------------------------------------------------------------------------------
 
  Button b = new Button(new EventHandler(onButtonAction));
b.clicked(1);
 
 
--------------------------------------------------------------------------------
 
  Button b = new Button();
b.ButtonClick += new ButtonEventHandler(onButtonAction);
b.clicked(1);
 
 
--------------------------------------------------------------------------------
 
  Button b = new Button();
b.ButtonClick += new ButtonEventHandler(onButtonAction);
b.clicked = True;
 
0
Comment
Question by:mathieu_cupryk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 17885773
None of the above.
0
 
LVL 35

Accepted Solution

by:
Raynard7 earned 250 total points
ID: 17885778
Below would be the correct method to add a button handler

Button b = new Button();
b.ButtonClick += new ButtonEventHandler(onButtonAction);

To trigger the event you should just be able to call the routine you delegated to button above, rather than setting a property of the button itself.
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17885795
Button does not have any contsructor that takes an argument, nor does it have any property, method or event called ButtonClick or clicked;
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17885805
Ah, unless this is some fantasy Button control you have written yourself in which case it could be either of the last two options depending on how you had written the control.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question