Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to all,
I need to use a common control say for example button for all forms. Whenever i call the button it should do the operation.
help me.

the button should be available in a common class. i should access that button to perform various operations.


Public Sub CloseClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim FormToClose As Form = CType(sender, Button).FindForm FormToClose.Close()
End Sub


AddHandler btnClose.Click, AddressOf CloseClick


in the above mentioned code i cannot add an extra argument.
why????????????????


please explain it clearly..
Posted
Updated 12-Mar-10 16:28pm
v5

I am not able to understand your question properly

I guess you should have to wrap your opration in share function.

by the way what do you mean by
"Whenever i call the button"

:)
 
Share this answer
 
The parameters have to stay the same as in an original Click event handler. If you need to pass in an argument, the best idea would be to use the buttons tag property, which can handle any object.
 
Share this answer
 
Hi there,
If I understand you correctly, you need to use one function to handle multiple buttons click events, the buttons being on different forms.
The way to do this is to have a Routine in an application level module, which will handle the events. Then in your Form Load event on each form, you add a delegate to this event and associate it with the buttons click event. An example would to best. Say you wanted one routine to handle all your separate forms close event. In your app level module you add your routine like this,

VB
Public Sub CloseClick(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Dim FormToClose As Form = CType(sender, Button).FindForm
        FormToClose.Close()

    End Sub

Then in each form you add your delegate like this,

AddHandler btnClose.Click, AddressOf CloseClick


hope this helps
 
Share this answer
 

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