473,625 Members | 2,615 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_e vents
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 1146
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********@wid getinc.comwrote in message
news:ac******** *************** ***********@j40 g2000prh.google groups.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_e vents
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.OnResiz e( ... )

* * 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********@wid getinc.coma écrit dans le message de
groupe de discussion :
5b************* *************** **...legroups .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.OnResiz e( ... )

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********@wid getinc.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********@wid getinc.coma écrit dans le message de
groupe de discussion :
e0************* *************** **...legroup s.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
11158
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 testing. Our custumer tries it serveral times and then the recovery works and the data are corrupt. I have written a little programm which does some selects to this database. The program is stopped during recovery but our customer beleves that...
3
1364
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 System::Drawing::Bitmap object. How can I get a reference to the .NET Bitmap, bypassing the CCW? ex:
4
1888
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 application. People have to login from http://mydomain.com/ to access the information on my site. For now, this is working fine. People cannot bypass the login form, any attempt to check out a page (if they happen to know the file name) will be...
0
2964
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 report directly to the printer bypassing the Crystal report viewer altogether. When sending the job directly to the printer I use the PrintToPrinter command CR.PrintToPrinter(1, False, 0, 0)
1
1890
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 and print laser deposit tickets. I use the following to set my printer: PrintDocument doc = new PrintDocument(); if (printer != "default") doc.PrinterSettings.PrinterName = printer; I then raise an event: doc.PrintPage += new...
10
5517
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 pressed, submit the form - bypassing my onclick handler. I can partially fix this with: <form onsubmit='return false;'>
4
2688
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 have become very long since we have 2 master pages that our pages inherit from. Some team members at
4
2136
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 think I want to show it will not show what is being generated from the database... and if I take the bypass out it works with no issues.... any ideas? // ------------------------------------------------------------------------------- //...
2
1150
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 possible to override whichever routine processes the event
0
8182
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8688
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7178
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6115
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1800
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.