List Info

Thread: Overload a EventHandler




Overload a EventHandler
user name
2006-03-06 12:11:38

You would need to create your own custom timer, which must inherit from System.Windows.Forms.Timer. ; Use the custom timer on your form, rather than the normal Timer control.

In your custom control you need to override the OnTick method.  In there you can decide which "overloaded event"; you want to fire - the event is raised by calling base.OnTick, passing in the EventArgs param you want included in the event So either include the "EventArgs e" that the event was going to fire, or replace it with a custom class that inherits from EventArgs.

So here's the custom timer class:

    // Custom Timer

    internal class MyTimer : System.Windows.Forms.Timer

    {

        internal bool MyEventCondition = false;

        protected override void OnTick(EventArgs e)

        {

           ; if (MyEventCondition)

           ;     base.OnTick(new MySpecialEventParams("I just wanna say ...",42));

           ; else

           ;     base.OnTick(e);

        }

    }

Here's the custom event args object.

    // Custom event args

    internal class MySpecialEventParams : EventArgs

    {

        internal string MyStringParam;

        internal int MyIntegerParam;

        internal MySpecialEventParams(string String, int Integer)

        {

           ; MyStringParam = String;

           ; MyIntegerParam = Integer;

        }

    }

And here's the relevant code from the parent form.  This code just toggles the event fire condition, so the first time the event is raised you get a standard EventArgs and the next, your custom one.

    public partial class Form1 : Form

    {

        public Form1()

        {

           ; InitializeComponent();

           ; timer1.Tick += new System.EventHandler(timer1_Tick);

           ; timer1.Interval = 5000;

           ; timer1.Enabled = true;

        }

        // Timer event handler

        void timer1_Tick(object sender, System.EventArgs e)

        {

           ; timer1.Enabled = false;

           ; if (e is MySpecialEventParams)

           ; {

           ;     MySpecialEventParams special = (MySpecialEventParams)e;

           ;     MessageBox.Show(special.MyStringParam);

           ; }

           ; else

           ;     MessageBox.Show("Just the normal tick event";);

           ; timer1.MyEventCondition = !timer1.MyEventCondition;

           ; timer1.Enabled = true;

        }

    }

Regards,

David Bridge

       



-----Original Message-----
From: CSDevelopersgooglegroups.com [googlegroups.com">mailto:CSDevelopersgooglegroups.com] On Behalf Of JoSo
Sent: 04 March 2006 21:04
To: C# Developers
Subject: Overload a EventHandler


Hey everybody!

I want to overload the timer.tick() method like tick(Sender s,

SystemEvtArg e, String my string)

Now I want to execute the method.

But what to put in for Sender and SystemsEvtArg?

Thx a lot

Cheers!


**********************************************************************

Please visit the official ITV website at www.itv.com

for the latest company news.

This email and any files transmitted are confidential and intended

solely for the use of the individual or entity to which they are

addressed. If you have received this email in error, please notify

postmasteritv.com

Thank you.

**********************************************************************

**********************************************************************
Please visit the official ITV website at www.itv.com
for the latest company news.

This email and any files transmitted are confidential and intended
solely for the use of the individual or entity to which they are
addressed. If you have received this email in error, please notify
postmasteritv.com

Thank you.
**********************************************************************
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C# Developers" group.
To post to this group, send email to CSDevelopersgooglegroups.com
To unsubscribe from this group, send email to CSDevelopers-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/CSDevelopers
-~----------~----~----~----~------~----~------~--~---
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )