473,508 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bypassing Events

Hello All,

I don't know if this is possible, but I'll give it a shot, here. I'm
sick of writing the following line of code in control event handlers:

if not visible then exit sub

Is it possible to override whichever routine processes the event
handler list so that no events are fired if the control is visible?
Something like this, for example:

protected overrides sub handle_events
if visible then mybase.handle_events
end sub 'handleEvents

(of course, I know that there's no handle_events routine, but is there
an equivalent?)

Please advise and tia,

rts
Nov 4 '08 #1
8 1141
I dont know if RemoveHandler would work.

You might be able to do everything in 'one sub / function' to add and remove
handlers.

But - when multiple events are raised at the same time you probably cant
guarantee you removehandler and addhandler would be processed first.

Miro

"Rex the Strange" <ro********@widgetinc.comwrote in message
news:ac**********************************@j40g2000 prh.googlegroups.com...
Hello All,

I don't know if this is possible, but I'll give it a shot, here. I'm
sick of writing the following line of code in control event handlers:

if not visible then exit sub

Is it possible to override whichever routine processes the event
handler list so that no events are fired if the control is visible?
Something like this, for example:

protected overrides sub handle_events
if visible then mybase.handle_events
end sub 'handleEvents

(of course, I know that there's no handle_events routine, but is there
an equivalent?)

Please advise and tia,

rts
Nov 4 '08 #2
Rex the Strange wrote:
I'm sick of writing the following line of code in control event
handlers:

if not visible then exit sub

Is it possible to override whichever routine processes the event
handler list so that no events are fired if the control is visible?
You're on the right track - you have to look at overriding here because,
by the time you're into an event handler, the event's already been
raised and it's too lateto do anything about it.

The conventional pattern for this sort of thing is something like this:

Class CustomLabel
Inherits Label

Protected Overrides Sub OnResize( ... )

If Not Me.Visible Then Return

MyBase.OnResize( ... )

End Sub

End Class

This approach will work with just about every event, using this
On[<event>] pattern.

Then just use your Custom Label instead of the standard one.

HTH,
Phill W.
Nov 5 '08 #3
On Nov 5, 7:26*am, "Phill W." <p-.-a-.-w-a-r...@-o-p-e-n-.-a-c-.-u-k>
wrote:
Rex the Strange wrote:
I'm sick of writing the following line of code in control event
handlers:
if not visible then exit sub
Is it possible to override whichever routine processes the event
handler list so that no events are fired if the control is visible?

You're on the right track - you have to look at overriding here because,
by the time you're into an event handler, the event's already been
raised and it's too lateto do anything about it.

The conventional pattern for this sort of thing is something like this:

Class CustomLabel
* * Inherits Label

* * Protected Overrides Sub OnResize( ... )

* * * *If Not Me.Visible Then Return

* * * *MyBase.OnResize( ... )

* * End Sub

End Class

This approach will work with just about every event, using this
On[<event>] pattern.

Then just use your Custom Label instead of the standard one.

HTH,
* * Phill *W.
I see. Not really the sort of solution I was looking for - this would
require overriding all native event handlers which is only one step
away from putting the code in each of my event handlers. I was hoping
there was a master function that I could override - one that calls the
handlers.

Oh well. Thanks, anyway, all.

rts.
Nov 5 '08 #4
You may want to explain what is the original problem you are trying to
solve.

It looks like you found that costlty events are triggered even when not
needed ? You could perhaps prevent them from happening by not touching the
control in the first place (what kind of events do you try to prevent ?)

Even and if you don't need much design time support you could create this
control as needed when needed. This way you don't have to change anything
when not visible, actually it doesn't event exists (or removing it from the
controls tree could perhaps work thought I never tried such a thing).

Or a wise use of the WndProc ?

Or Phil solution possibly with overriding the Visible property to
automatically remove/add the handlers depending on the new and current value
etc...

Or is it just in a control you are creating ? (in which case I don't see any
other solution).

etc...

--
Patrice

"Rex the Strange" <ro********@widgetinc.coma écrit dans le message de
groupe de discussion :
5b**********************************...oglegroups.com...
On Nov 5, 7:26 am, "Phill W." <p-.-a-.-w-a-r...@-o-p-e-n-.-a-c-.-u-k>
wrote:
>Rex the Strange wrote:
I'm sick of writing the following line of code in control event
handlers:
if not visible then exit sub
Is it possible to override whichever routine processes the event
handler list so that no events are fired if the control is visible?

You're on the right track - you have to look at overriding here because,
by the time you're into an event handler, the event's already been
raised and it's too lateto do anything about it.

The conventional pattern for this sort of thing is something like this:

Class CustomLabel
Inherits Label

Protected Overrides Sub OnResize( ... )

If Not Me.Visible Then Return

MyBase.OnResize( ... )

End Sub

End Class

This approach will work with just about every event, using this
On[<event>] pattern.

Then just use your Custom Label instead of the standard one.

HTH,
Phill W.

I see. Not really the sort of solution I was looking for - this would
require overriding all native event handlers which is only one step
away from putting the code in each of my event handlers. I was hoping
there was a master function that I could override - one that calls the
handlers.

Oh well. Thanks, anyway, all.

rts.

Nov 5 '08 #5
You may want to explain what is the original problem you are trying to
solve.
It's not really a problem to be solved - more that I would like to
increase performance by not running the handler code for controls that
aren't going to be shown in the end, anyway.
It looks like you found that costlty events are triggered even when not
needed ?
That's exactly it. I can live with these handlers being called and
then exiting from them if the control is not visible (which is the way
I currently do it) but I just think that it would be nicer if I could
run this test in one place for all handlers. Surely there's a routine
that marches through the control list and fires the events? What is
that routine and is it overridable?

Nov 6 '08 #6
On Thu, 6 Nov 2008 09:38:36 -0800 (PST), Rex the Strange
<ro********@widgetinc.comwrote:
>
>You may want to explain what is the original problem you are trying to
solve.

It's not really a problem to be solved - more that I would like to
increase performance by not running the handler code for controls that
aren't going to be shown in the end, anyway.
>It looks like you found that costlty events are triggered even when not
needed ?

That's exactly it. I can live with these handlers being called and
then exiting from them if the control is not visible (which is the way
I currently do it) but I just think that it would be nicer if I could
run this test in one place for all handlers. Surely there's a routine
that marches through the control list and fires the events? What is
that routine and is it overridable?
In general there is no method that "marches through the control list"
to fire events. Each event does something specific to that event.
When a control is resized, the SizeChanged event is fired for each of
its children. Keyboard events raise events in the control with focus.
Mouse events raise events in the control underneath the mouse.

You have to be very careful if you want to simply ignore all events
when a control is not visible. You may need to fix things up when the
control becomes visible.

For example, suppose you have a control that is anchored to the bottom
of a form. If the control is invisible when the form is resized, and
you block events to the control, when the control becomes visible it
will be in the wrong place.

What events are you trying to not process?
Nov 6 '08 #7
See Jack advice, wether or not it is a good idea may also depend on what
exactly you cancel as if the control is finally visible again its state
could be wrong.

If this is just something you "feel" would be quicker, you may want to
measure actual performance before doing such a change.

Also if you have actual performance problem, you could also investigate if
this is not a design or algorhitm issue (such as something causing a bunch
of events being triggered or something such as filling a list the wrong way
etc...)

If you have a problem generally it's better to ask about the original
problem rather than about the solution you try to apply, as describing the
original problem could lead someone to suggest a much better solution...
--
Patrice

"Rex the Strange" <ro********@widgetinc.coma écrit dans le message de
groupe de discussion :
e0**********************************...oglegroups.com...
>
>You may want to explain what is the original problem you are trying to
solve.

It's not really a problem to be solved - more that I would like to
increase performance by not running the handler code for controls that
aren't going to be shown in the end, anyway.
>It looks like you found that costlty events are triggered even when not
needed ?

That's exactly it. I can live with these handlers being called and
then exiting from them if the control is not visible (which is the way
I currently do it) but I just think that it would be nicer if I could
run this test in one place for all handlers. Surely there's a routine
that marches through the control list and fires the events? What is
that routine and is it overridable?
Nov 6 '08 #8
I just had a realization - and, yes, Jack, I appreciate your argument.
I did not make myself very clear, however. I'm actually talking about
asp.net, not applications development. I apologize for not making this
distinction earlier in the discussion.

In asp.net (using VB - perhaps I'm in the wrong discussion group?) all
events are processed before the page is rendered and it's these events
I'm talking about.

Sorry about the confusion.
Nov 6 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
11147
by: Jens Kalkbrenner | last post by:
MS SQL-Server 7.0 Bypassing recovery for database 'EfW_765' because it is marked IN LOAD. What does this mean? Our customer is backing up is maindatabase and is recovering it to this database for...
3
1359
by: Eric St-Onge | last post by:
Hi, I have a DLL that exposes COM interfaces. One of the COM Object receives an IDispatch pointer. I know that this IDispatch pointer is in fact a COM Callable Wrapper for a...
4
1884
by: antonyliu2002 | last post by:
Let me try to make clear what my concern is. I think it is a pretty interesting one, which I think of while I am developing my web application. I have an authenticated/authorized web...
0
2943
by: John Smith | last post by:
Hello, I am developing a VB.NET 2003 application that will use lots of Crystal Reports. Sometimes the users will preview a report in a Crystal report viewer, and sometimes they will send the...
1
1888
by: =?Utf-8?B?QXVzdGluIFN0ZXBoZW5z?= | last post by:
In my commercial financial application I run a deposit report. I use an option to copy the report to the Clipboard. I then run a .NET consol app to “grab†the Clipboard and format the data...
10
5505
by: Tim Streater | last post by:
I have a form and a button to submit it. The button is made from: <input type=button onclick='myHandler(this.form);'> This all works fine except that in Safari 2.0.4, the enter/return keys, if...
4
2675
by: TS | last post by:
Steven, i lost this message conversation from outlook express and made a post online (see last one on this page). Please answer it as it hasn't been yet. thanks The clientID of our controls...
4
2124
Chrisjc
by: Chrisjc | last post by:
The question at hand is I bypass an array in column 4... but I also have something else that should be going in there from the database but because I am bypassing it and forcing it to show the ony...
2
1143
by: Rex the Strange | last post by:
Hello All, I don't know if this is possible, but I'll give it a shot, here. I'm sick of writing the following line of code in control event handlers: if not visible then exit sub Is it...
0
7124
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1558
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.