Button Click Event Handling

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Hi,

I would like to have a custom event handler attached to th click event of a
button:

btnTmp.Click += new CustomeEventHandler(EventHandler);

I have tried searching for an example of this, but have not had any luck -
can anyone help?

Mark
 
* "Mark said:
I would like to have a custom event handler attached to th click event of a
button:

btnTmp.Click += new CustomeEventHandler(EventHandler);

I have tried searching for an example of this, but have not had any luck -
can anyone help?

Have a look at the "Designer Generated Code". There you will see how to
add an event handler to a button's 'Click' event if you added a button +
'Click' event handler previously.
 
AddHandler btnTmp.Click, AddressOf EventHandlerSub

Public sub EventHandlerSub(sender as object, e as eventargs)
End sub

HTH
 
Hi,

Many thanks for the reply, but I think you have misunderstood what I would
like to do (probably because I'm not good at explaining things)

I would like a custom event fired when the user clicks on the button. I am
try to implement a context menu for a datagrid (which is working). However
when the user selects edit I would like the primary key (int) to be sent as
a parameter to a method that would handle the event.

Mark
 
Another option, if you are just trying to create a reusable method for
handling the edit, is to create the method you wish to handle it and include
the primary key in the call to that method, then call that method from the
click event handler.

And, if you want a pretty decent tutorial on creating custom events in cases
where you can use them, look up "EventArgs Class" in the Framework SDK
Documentation.

Dale

Paul said:
Perhaps you can save your primary key in the form's implementation,
instead of passing it to the callback method. The form is running in STA
thread so there's no threading issue.
An alternative is to subclass the Button class and expose your custom
Event and Delegate and bootstrap on Button's Click event. You just can't
subclass a delegate for security reasons.
 
Back
Top