PC Review


Reply
Thread Tools Rate Thread

Trapping all events

 
 
Raju Shrestha
Guest
Posts: n/a
 
      10th Dec 2003
Is there anyway to trap all events to have centralized control?

Let me try to make the problem clear. Suppose I have a form and several
many controls on it. As we know every control has its own events and
according to certain actions(by user, system etc.), corresponding event
gets fired. I am trying to centralize the event handling to handle all
events of the form and its containing controls in one procedure
something like:
Sub EventFired(source As Object, event As ???, args As EventArgs)
' source identifies the control say source.Name gives BtnOk, event
should give the fired event, say BtnOk.Click o r just Click, args gives
the arguments for the event
.....
..... code to identify the source of event, event type and event
arguments and can control whether to let the event gets fired or cancel
.....
If (condition1) Then
args.Cancel = True ' cancels the event being fired
End If
End Sub

Can this be done? If so how? Appreciate for the ideas, comments and
solutions.

Thanks

Raju Shrestha

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Jan Tielens
Guest
Posts: n/a
 
      10th Dec 2003
I'm not aware of a "magical" line of code that could do this. But you can
always attach an event handler manually to any event, using the AddHandler
statement in VB.NET. You could use for all events the same handler (e.g. sub
EventFired).

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan


"Raju Shrestha" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there anyway to trap all events to have centralized control?
>
> Let me try to make the problem clear. Suppose I have a form and several
> many controls on it. As we know every control has its own events and
> according to certain actions(by user, system etc.), corresponding event
> gets fired. I am trying to centralize the event handling to handle all
> events of the form and its containing controls in one procedure
> something like:
> Sub EventFired(source As Object, event As ???, args As EventArgs)
> ' source identifies the control say source.Name gives BtnOk, event
> should give the fired event, say BtnOk.Click o r just Click, args gives
> the arguments for the event
> .....
> ..... code to identify the source of event, event type and event
> arguments and can control whether to let the event gets fired or cancel
> .....
> If (condition1) Then
> args.Cancel = True ' cancels the event being fired
> End If
> End Sub
>
> Can this be done? If so how? Appreciate for the ideas, comments and
> solutions.
>
> Thanks
>
> Raju Shrestha
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      10th Dec 2003
* Raju Shrestha <(E-Mail Removed)> scripsit:
> Let me try to make the problem clear. Suppose I have a form and several
> many controls on it. As we know every control has its own events and
> according to certain actions(by user, system etc.), corresponding event
> gets fired. I am trying to centralize the event handling to handle all
> events of the form and its containing controls in one procedure
> something like:
> Sub EventFired(source As Object, event As ???, args As EventArgs)
> ' source identifies the control say source.Name gives BtnOk, event
> should give the fired event, say BtnOk.Click o r just Click, args gives
> the arguments for the event
> .....
> ..... code to identify the source of event, event type and event
> arguments and can control whether to let the event gets fired or cancel
> .....
> If (condition1) Then
> args.Cancel = True ' cancels the event being fired
> End If
> End Sub


Maybe with reflection + 'AddHandler'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trapping KeyDown Events HaySeed Microsoft Dot NET Framework Forms 0 28th Dec 2008 04:40 AM
Trapping Excel events in c# =?Utf-8?B?VGltIE0=?= Microsoft Excel Programming 0 14th Mar 2006 06:19 PM
Trapping events Jimbo Microsoft Outlook Interoperability 1 25th May 2005 01:45 PM
xpburncd dll - trapping its events Bernie Yaeger Microsoft VB .NET 1 24th Jan 2005 07:14 AM
Trapping Another Windows Events Mr Sparkles Microsoft C# .NET 2 11th Aug 2003 12:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:13 PM.