Add Event that is viewable..

B

Brett Wickard

How do I add an event to an object (in this case a form) that is viewable in
the GUI of VS2005?

i.e. if I add the following to a form:
public delegate void TestDelegate(int Test);

public static event TestDelegate TestEvent;



For some reason I can't see this new event in the Properties/Events of the
VS2005 GUI... How can I make it appear there?
 
M

Marc Gravell

Woah - now your exposing all sorts of access that people generally hide
via the "event" accessors...

My first guess would be that the IDE only supports adding *instance*
events, not *static* events, which makes a lot of sense for forms.

My second guess would be that the IDE wants you to follow the standard
pattern:

public delegate void SomeTestHandler(object sender, SomeTestEventArgs
args);

where SomeTestEventArgs : EventArgs, probably exposing the integer as a
property:

public class SomeTestEventArgs : EventArgs {
public readonly int TestValue; // probably better a property
public SomeTestEventArgs(int testValue) {TestValue=testValue;}
}

Note that in 2.0 you can also then dispose of the custom delegate,
using instead

public event EventHandler<SomeTestEventArgs> TestEvent;

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top