Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2004

Tip: Looking for answers? Try searching our database.

Generic button click event

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mark - 22 Oct 2004 01:19 GMT
Is there a means of raising an event when ANY button on a windows application
form is clicked wherein the actual button clicked can be determined in the
generic click events code (eg by way of interogating the sender)?
Signature

mark

jjardine - 22 Oct 2004 02:10 GMT
> Is there a means of raising an event when ANY button on a windows
> application
> form is clicked wherein the actual button clicked can be determined in the
> generic click events code (eg by way of interogating the sender)?

you could create a generic event and add all of the buttons to it in the
Handles clause.
scorpion53061 - 22 Oct 2004 02:27 GMT
The DirectCast statement simply converts the "sender" variable (which is
declared as an Object) to a Button. Essentially, if you click on Button1
you
get Button1 passed to the Click event handler as an object. Cast it back
to
a Button and you can do anything you want with it including accessing
it's
properties such as name, text, position, etc....

See this discussion for some more information. It's a very similar
problem... at least the part about adding multiple buttons...

http://www.devcity.net/forums/topic.asp?tid=4087&page=2

Remember in VB.NET you can have a single event handler handle multiple
events (as above) and you can have a single event handled by multiple
handlers...

Private Sub Stuff1(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
End Sub

Private Sub Stuff2(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MenuItem2.Click
End Sub

Private Sub Stuff3(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MenuItem2.Click,
Button1.Click

End Sub

In the above if you click Button1: Stuff1 & Stuff3 will execute, if you
click MenuItem2: Stuff2 & Stuff3 will execute.

In addition to the Handles keyword, you can use AddHandler &
RemoveHandler
to handle an event.

> Is there a means of raising an event when ANY button on a windows
> application
> form is clicked wherein the actual button clicked can be determined in the
>
> generic click events code (eg by way of interogating the sender)?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.