event help needed (events with string name parameters) 
Author Message
 event help needed (events with string name parameters)

I need to be able to add an event that has a string name associated with it,
for example:

Event("Some Name") += new Delegate(SomeFunction);
Event("Some Other Name") += new Delegate(SomeOtherFunction);

The class will know what to do with the string "Some Name" all I need to do
is figure out the syntax for a function that can relate the strings when
setting the delegate and firing the event.

I have explored the use of a hashtable of events but it is not clear how to
fully specify the string name for the hashtable and then call the event, in
the msdn example the hash table names are hardcoded and I need to set them
on the fly.

Thanks,

Mike



Fri, 04 Mar 2005 23:49:18 GMT  
 event help needed (events with string name parameters)
Hello Mike

You may use Reflection to get the method from the type first. And then call
it AddEventHandler method to add a hander to this event. There is a sample
code demonstrates adding a MouseMove event handler to the current Form:

private void button1_Click(object sender, System.EventArgs e)
{
        Type typ = this.GetType();
        EventInfo evn = typ.GetEvent("MouseMove");
        evn.AddEventHandler(this, new
System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove));

Quote:
}

private void Form1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
        Console.WriteLine(e.ToString());

Quote:
}

I hope this helps you.

Best regards,

Lion Shi [MS}
MCSE, MCSD
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.  2001 Microsoft Corporation. All rights
reserved.
--------------------

    Subject: event help needed (events with string name parameters)
    Date: Mon, 16 Sep 2002 11:49:18 -0400
    Lines: 20
    X-Priority: 3
    X-MSMail-Priority: Normal
    X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
    X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000

    Newsgroups: microsoft.public.dotnet.languages.CSharp
    NNTP-Posting-Host: 66.157.192.111
    Path: cpmsftngxa08!cpmsftngxa07!tkmsftngp01!tkmsftngp12
    Xref: cpmsftngxa08 microsoft.public.dotnet.languages.csharp:92767
    X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

    I need to be able to add an event that has a string name associated
with it,
    for example:

    Event("Some Name") += new Delegate(SomeFunction);
    Event("Some Other Name") += new Delegate(SomeOtherFunction);

    The class will know what to do with the string "Some Name" all I need
to do
    is figure out the syntax for a function that can relate the strings when
    setting the delegate and firing the event.

    I have explored the use of a hashtable of events but it is not clear
how to
    fully specify the string name for the hashtable and then call the
event, in
    the msdn example the hash table names are hardcoded and I need to set
them
    on the fly.

    Thanks,

    Mike



Sun, 06 Mar 2005 23:53:29 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. AcitveX event names as strings?

2. HELP: COM events and Network events

3. Fire an Event, sink a event - Help!

4. C++ Event needs string arg that can be passed to VB

5. Need help with inheritted events

6. Help Needed: Events (Key Press)

7. Need help with compiling a message table for event log

8. Need help with Serial Comms Events in MSCOMM

9. Help needed on Event Logging (NT)

10. Need help ... Event not firing in Releasemode

11. Need help in Implementing Events

12. DLL help needed: string-parameter problem

 

 
Powered by phpBB® Forum Software