473,671 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delegates and EventHandlers

I need some assistance doing some "right way to do it" coding. The following
are EventHandlers associated with Delegates in a child form that call a
procedure in the MDI form that resets a timer. There must be a better way to
code this than calling OnResetTimer in all these procedures separately. Is
there not a way to use one handler for all of them?

private void pnlCPI_MouseMov e(object sender,
System.Windows. Forms.MouseEven tArgs e)
{
OnResetTimer(th is);
}

private void txtCPI_KeyPress (object sender,
System.Windows. Forms.KeyPressE ventArgs e)
{
OnResetTimer(th is);
}

private void dgLevelOfCare_M ouseMove(object sender,
System.Windows. Forms.MouseEven tArgs e)
{
OnResetTimer(th is);
}

private void dgLevelOfCare_K eyPress(object sender,
System.Windows. Forms.KeyPressE ventArgs e)
{
OnResetTimer(th is);
}
--
Robert Hill

Nov 17 '05 #1
3 1878
Robert,

Is OnResetTimer your own method? Change it's signature to be:

private void OnResetTimer(ob ject sender, EventArgs e)

then in Form's designer property page switch to Events view (an icon with a
thunderbolt). Now select the control you want and OnResetTimer should appear
in a dropdown list and you can assign it to events you want.

Alternatively, just FYI, you could override WndProc and reset timer there
(sorry, don't have examples right now).

HTH,
Alexander

"Robert" <rh******@hotma il.com> wrote in message
news:99******** *************** ***********@mic rosoft.com...
I need some assistance doing some "right way to do it" coding. The
following
are EventHandlers associated with Delegates in a child form that call a
procedure in the MDI form that resets a timer. There must be a better way
to
code this than calling OnResetTimer in all these procedures separately.
Is
there not a way to use one handler for all of them?

private void pnlCPI_MouseMov e(object sender,
System.Windows. Forms.MouseEven tArgs e)
{
OnResetTimer(th is);
}

private void txtCPI_KeyPress (object sender,
System.Windows. Forms.KeyPressE ventArgs e)
{
OnResetTimer(th is);
}

private void dgLevelOfCare_M ouseMove(object sender,
System.Windows. Forms.MouseEven tArgs e)
{
OnResetTimer(th is);
}

private void dgLevelOfCare_K eyPress(object sender,
System.Windows. Forms.KeyPressE ventArgs e)
{
OnResetTimer(th is);
}
--
Robert Hill

Nov 17 '05 #2
OnResetTimer is my owm method in a MDI form. It is being called from a child
form of the MDI firm using Delegates and EventHandlers. The deal is that the
user has to log back into the application if there is no activity in 30
minutes. I have a timer on the MDI form that gets reset everytime there is
activity such as MouseMove or KeyPress on a child form. I have no EventArgs
to pass back to the OnResetTimer method so I am just passing back the sender.
I am just looking for a more elegant way to handle the call to OnResetTimer.

Thanks,

Robert

"Alexander Shirshov" wrote:
Robert,

Is OnResetTimer your own method? Change it's signature to be:

private void OnResetTimer(ob ject sender, EventArgs e)

then in Form's designer property page switch to Events view (an icon with a
thunderbolt). Now select the control you want and OnResetTimer should appear
in a dropdown list and you can assign it to events you want.

Alternatively, just FYI, you could override WndProc and reset timer there
(sorry, don't have examples right now).

HTH,
Alexander

"Robert" <rh******@hotma il.com> wrote in message
news:99******** *************** ***********@mic rosoft.com...
I need some assistance doing some "right way to do it" coding. The
following
are EventHandlers associated with Delegates in a child form that call a
procedure in the MDI form that resets a timer. There must be a better way
to
code this than calling OnResetTimer in all these procedures separately.
Is
there not a way to use one handler for all of them?

private void pnlCPI_MouseMov e(object sender,
System.Windows. Forms.MouseEven tArgs e)
{
OnResetTimer(th is);
}

private void txtCPI_KeyPress (object sender,
System.Windows. Forms.KeyPressE ventArgs e)
{
OnResetTimer(th is);
}

private void dgLevelOfCare_M ouseMove(object sender,
System.Windows. Forms.MouseEven tArgs e)
{
OnResetTimer(th is);
}

private void dgLevelOfCare_K eyPress(object sender,
System.Windows. Forms.KeyPressE ventArgs e)
{
OnResetTimer(th is);
}
--
Robert Hill


Nov 17 '05 #3
Here's the version with overriding WndProc if for some reason you didn't
like my previous solution:

private const int WM_KEYFIRST = 0x0100;
private const int WM_KEYLAST = 0x0108;

private const int WM_MOUSEFIRST = 0x0200;
private const int WM_MOUSELAST = 0x020A;

protected override void WndProc(ref Message m)
{
if (m.Msg >= WM_KEYFIRST & m.Msg <= WM_KEYLAST)
{
OnResetTimer(th is);
}

if (m.Msg >= WM_MOUSEFIRST & m.Msg <= WM_MOUSELAST)
{
OnResetTimer(th is);
}

base.WndProc (ref m);
}

"Robert" <rh******@hotma il.com> wrote in message
news:D3******** *************** ***********@mic rosoft.com...
OnResetTimer is my owm method in a MDI form. It is being called from a
child
form of the MDI firm using Delegates and EventHandlers. The deal is that
the
user has to log back into the application if there is no activity in 30
minutes. I have a timer on the MDI form that gets reset everytime there
is
activity such as MouseMove or KeyPress on a child form. I have no
EventArgs
to pass back to the OnResetTimer method so I am just passing back the
sender.
I am just looking for a more elegant way to handle the call to
OnResetTimer.

Thanks,

Robert

"Alexander Shirshov" wrote:
Robert,

Is OnResetTimer your own method? Change it's signature to be:

private void OnResetTimer(ob ject sender, EventArgs e)

then in Form's designer property page switch to Events view (an icon with
a
thunderbolt). Now select the control you want and OnResetTimer should
appear
in a dropdown list and you can assign it to events you want.

Alternatively, just FYI, you could override WndProc and reset timer there
(sorry, don't have examples right now).

HTH,
Alexander

"Robert" <rh******@hotma il.com> wrote in message
news:99******** *************** ***********@mic rosoft.com...
>I need some assistance doing some "right way to do it" coding. The
>following
> are EventHandlers associated with Delegates in a child form that call
> a
> procedure in the MDI form that resets a timer. There must be a better
> way
> to
> code this than calling OnResetTimer in all these procedures separately.
> Is
> there not a way to use one handler for all of them?
>
> private void pnlCPI_MouseMov e(object sender,
> System.Windows. Forms.MouseEven tArgs e)
> {
> OnResetTimer(th is);
> }
>
> private void txtCPI_KeyPress (object sender,
> System.Windows. Forms.KeyPressE ventArgs e)
> {
> OnResetTimer(th is);
> }
>
> private void dgLevelOfCare_M ouseMove(object sender,
> System.Windows. Forms.MouseEven tArgs e)
> {
> OnResetTimer(th is);
> }
>
> private void dgLevelOfCare_K eyPress(object sender,
> System.Windows. Forms.KeyPressE ventArgs e)
> {
> OnResetTimer(th is);
> }
> --
> Robert Hill
>



Nov 17 '05 #4

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

Similar topics

4
10946
by: Greg Patrick | last post by:
Let's say I have a Form and I create a delegate (MyDelegate) and an event (SomethingHappened) for that form. Now other classes add their delegate to the event, e.g. theForm.SomethingHappened += new MyDelegate(this.myMethod); When I Close the form, how do I properly dispose of the delegates of the event? Does each subcriber need to do a -= ?
5
2771
by: JMWilton | last post by:
Is there a way to determine what has been added to the eventhandler list? I have code that uses += and -= to turn event handling code on and off. Apparently, it is possible to add the same event handler more than once. Documentation refers to a Delegate invocationlist...but I can't seem to access it from C#. I am looking for a way to ensure that the contents of the eventhandler list is "well known".
4
22876
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on when to use one over another? If anyone could provide any additional info, your comments, best practices, any good articles, specific examples, etc. Thank you
1
1353
by: Timo | last post by:
I haven't tried coding eventhandlers in Global.asax yet -- any "gotchas" I should be aware of? Do programming errors there require bouncing IIS? Will handlers in Global.asax be able to access custom name/value pairs established in web.config (e.g. <add key="foo" value="bar" /> ) using ConfigurationSettings.AppSettings("foo") syntax? Thanks Timo
3
2951
by: Armin | last post by:
Hello I have a UserControl with a Click Event. Is it possible to find out the List of all Delegates/Eventhandlers using the Event. I read something about a "getinvocationlist" Methode for Delegates which can get this back, but couldN#t found out how it works.
0
4766
by: bharathreddy | last post by:
Delegates Here in this article I will explain about delegates in brief. Some important points about delegates. This article is meant to only those who already know delegates, it will be a quick review not a detailed one. Delegates quite simply are special type of object, a delegate just contains the details of a method. One good way to understanding delegates is by thinking of delegates as something that gives a name to a method...
6
2653
by: =?Utf-8?B?T2xkQ2FEb2c=?= | last post by:
My question is regarding the use of delegates in C#. I see how .Net uses delegates to wire event handlers to events. It’s an object created by a single line of code by the system and that makes perfect sense to me. I understand that there is a lot of code underneath that the system has created that makes it all work, thereby making it pretty efficient for the programmer. Outside of the use of delegates to wire event handlers, you can...
7
3416
by: Siegfried Heintze | last post by:
I'm studying the book "Microsoft Visual Basic.NET Language Reference" and I would like some clarify the difference between events and delegates. On page 156 I see a WinForms example of timer that uses the "WithEvents" and events. There is another example on page 124 that shows how to use delegates to sort an array. I don't understand the difference between events and delegates. Are they redundant features? How do I decide which to use? ...
69
5565
by: raylopez99 | last post by:
They usually don't teach you in most textbooks I've seen that delegates can be used to call class methods from classes that are 'unaware' of the delegate, so long as the class has the same signature for the method (i.e., as below, int Square (int)). Here is an example to show that feature. Note class "UnAwareClass" has its methods Square and Cuber called by a class DelegateClass. This is because these methods in UnAwareClass have the...
0
8924
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
8823
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
8672
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...
1
6234
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
5702
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
4412
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2817
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 we have to send another system
2
2058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1814
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.