Hello all,

I have a form with several controls(buttons) on it. I want
to start a screen saver after nothing has been pressed for
10 min. And of course if something has been pressed, to
restart the timer. To to this I have to trap each
control's Click event and restart the timer from there. Is
there a way to do this only once, somehow to hook before
each control's Click event or something sismilar?
Is there a way the form to intercept an event going one of
its controls?

Thank you

Re: Intercepting events by Brian

Brian
Sat Jul 12 23:14:56 CDT 2003

Hey.

How about...

create another event handler:

private void anyButton_Click( object sender, System.EventArgs e )
{
tmrStartScreenSaver.Enabled = false;
tmrStartScreenSaver.Enabled = true;
}

To save typing connecting up your events:

public Form1()
{
InitializeComponents();

foreach( Control control in this.Controls )
if( control is Button )
control.Click += new EventHandler( this.anyButton_Click );
}

If this makes sense, you're probably using C#. If your using VB.NET it will
be more of a problem.

Brian.

"joe" <j_sm2000@hotmail.com> wrote in message
news:002e01c348e8$b176eec0$a001280a@phx.gbl...
> Hello all,
>
> I have a form with several controls(buttons) on it. I want
> to start a screen saver after nothing has been pressed for
> 10 min. And of course if something has been pressed, to
> restart the timer. To to this I have to trap each
> control's Click event and restart the timer from there. Is
> there a way to do this only once, somehow to hook before
> each control's Click event or something sismilar?
> Is there a way the form to intercept an event going one of
> its controls?
>
> Thank you



Re: Intercepting events by joe

joe
Sun Jul 13 04:31:30 CDT 2003

the problem is that I already have separate handlers for
the buttons
>-----Original Message-----
>Hey.
>
>How about...
>
>create another event handler:
>
>private void anyButton_Click( object sender,
System.EventArgs e )
>{
> tmrStartScreenSaver.Enabled = false;
> tmrStartScreenSaver.Enabled = true;
>}
>
>To save typing connecting up your events:
>
>public Form1()
>{
> InitializeComponents();
>
> foreach( Control control in this.Controls )
> if( control is Button )
> control.Click += new EventHandler(
this.anyButton_Click );
>}
>
>If this makes sense, you're probably using C#. If your
using VB.NET it will
>be more of a problem.
>
>Brian.
>
>"joe" <j_sm2000@hotmail.com> wrote in message
>news:002e01c348e8$b176eec0$a001280a@phx.gbl...
>> Hello all,
>>
>> I have a form with several controls(buttons) on it. I
want
>> to start a screen saver after nothing has been pressed
for
>> 10 min. And of course if something has been pressed, to
>> restart the timer. To to this I have to trap each
>> control's Click event and restart the timer from there.
Is
>> there a way to do this only once, somehow to hook before
>> each control's Click event or something sismilar?
>> Is there a way the form to intercept an event going one
of
>> its controls?
>>
>> Thank you
>
>
>.
>

Re: Intercepting events by Brian

Brian
Sun Jul 13 09:16:28 CDT 2003

Because in C# you add the event handlers manually...
mycontrol.someEvent += new EventHandler( this.myEventHandler )

in VB.net... oh, wait I just looked it up, there's actually 2 ways in VB.

If you were connecting your events using Handles you'd have to type them
manually but you can do the same as C# by using AddHandler
(I learnt something new today and it's only 10:00 on a Sunday).

I'm not sure how things will work if Handles is used for the normal event
and AddHandler for the reset timer event, but it's easy enough to test.

There goes one of the reasons I prefer C#. I think I'll just pretend it
never happened.

Brian.

"Herfried K. Wagner" <aon.912666908.N.O.S.P.@.M.aon.at> wrote in message
news:OOIKOPTSDHA.2092@TK2MSFTNGP10.phx.gbl...
> Hello,
>
> "Brian" <acecool@rogers_removethis_.com> schrieb:
> > How about...
> >
> > create another event handler:
> >
> > private void anyButton_Click( object sender, System.EventArgs e )
> > {
> > tmrStartScreenSaver.Enabled = false;
> > tmrStartScreenSaver.Enabled = true;
> > }
> >
> > To save typing connecting up your events:
> >
> > public Form1()
> > {
> > InitializeComponents();
> >
> > foreach( Control control in this.Controls )
> > if( control is Button )
> > control.Click += new EventHandler( this.anyButton_Click );
> > }
> >
> > If this makes sense, you're probably using C#. If yur using
> > VB.NET it will be more of a problem.
>
> Why?
>
> Regards,
> Herfried K. Wagner
> --
> MVP · VB Classic, VB .NET
> http://www.mvps.org/dotnet
>
>



Re: Intercepting events by Herfried

Herfried
Sun Jul 13 10:00:45 CDT 2003

Hello,

"Brian" <acecool@rogers_removethis_.com> schrieb:
> Because in C# you add the event handlers manually...
> mycontrol.someEvent += new EventHandler( this.myEventHandler )
>
> in VB.net... oh, wait I just looked it up, there's actually 2 ways
> in VB.

;-)

> If you were connecting your events using Handles you'd
> have to type them manually but you can do the same as
> C# by using AddHandler (I learnt something new today and
> it's only 10:00 on a Sunday).
>
> I'm not sure how things will work if Handles is used for the
> normal event and AddHandler for the reset timer event, but it's
> easy enough to test.

You can disable a "Handles" event handler by calling RemoveHandler and
re-add it by calling AddHandler.

Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet