Setting up an event handler on a user-defined control



As a newbie I have been trying to set up an event handler
in my user-defined control to trigger an event in my form
when lblSelectedClient.Text changes. I get an error on my
event definition (****error here on event - says expected
class, delegate, enum, interface or struct ****). The
code is below. Can anyone see what I've done wrong?? I'm
at a loss.


public class ClientSearchEventArgs : EventArgs
public readonly string selectedClient;
public ClientSearchEventArgs(string selectedClient)
this.selectedClient = selectedClient;

//define the prototype of the callback method
public delegate void ChangedEventHandler(
object sender, ClientSearchEventArgs args);

//define the event
public event ChangedEventHandler Changed;
****error here on event - says expected class, delegate,
enum, interface of struct ****

//notify the registered objects of the event
protected virtual void OnChanged(
ClientSearchEventArgs e)
//if any object registered with the event
if (Changed != null)
//notify that object
Changed(this, e);

//Fire Change event when there is any
//change to the lblSelectedClient Text
//(attached to TextChanged event)
private void lblSelectedClient_TextChanged(object
sender, System.EventArgs e)
ClientSearchEventArgs args = new


Sorry folks, I've sorted it myself. It all came down to
one bracket in the end. I had this code within the
namespace rather than within the class! This bracket
thing is a real pain.

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