Wrox Programmer Forums
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 9th, 2003, 09:42 PM
Registered User
Join Date: Dec 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trapping all events

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.


Old December 10th, 2003, 12:45 PM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

(Nothing like asking for ideas and comments to open yourself up to soapbox preachers! ;))

This idea seems to just completely waste the point of event driven programming. Is it so hard to test for the given condition in each handler? What about disabling controls based on conditions? Example: When a condition is reached and a certain button should not be "clickable" because of that condition, just disable the button.

If you actually wanted to try to do this, then you'll have a lot of work to do. You could derive your own set of controls from the standard controls and handle the controls events in your own specialized way (i.e. raise a common event).

Frankly, the whole idea you pose seems odd and defeats the purpose of the event driven programming paradigm.

Work smarter, not harder.

Similar Threads
Thread Thread Starter Forum Replies Last Post
error trapping majones@omaha Classic ASP Basics 0 January 5th, 2006 02:02 PM
Trapping Application Events ERROR MagicTH Excel VBA 1 August 14th, 2005 01:23 PM
Need some error trapping... cpk Classic ASP Databases 4 January 26th, 2005 08:10 AM
Trapping Delete in the Datagrid jraymond VB.NET 2002/2003 Basics 5 July 10th, 2003 04:59 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.