Event Handler
-
A question ... I have 2 classes .. in a class1 (form) I call a function, situated in class2, for draw an image. In the middle of this function, i want send an event to class1 (for invalidate a rect etc) ... can you help me, with an example, to implement an event handler? thanks a lot.
Alex
-
A question ... I have 2 classes .. in a class1 (form) I call a function, situated in class2, for draw an image. In the middle of this function, i want send an event to class1 (for invalidate a rect etc) ... can you help me, with an example, to implement an event handler? thanks a lot.
Alex
public class Class1
{
private Class2 class2;
public Class1()
{
class2 = new Class2();
class2.Class2Event += new EventHandler(class2_Class2Event);
class2.Class2Function();
}void class2\_Class2Event(object sender, EventArgs e) { // Respond to event here }
}
public class Class2
{
public event EventHandler Class2Event;public void Class2Function() { OnClass2Event(EventArgs.Empty); } protected virtual void OnClass2Event(EventArgs e) { EventHandler eh = Class2Event; if (eh != null) eh(this, e); }
}
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
public class Class1
{
private Class2 class2;
public Class1()
{
class2 = new Class2();
class2.Class2Event += new EventHandler(class2_Class2Event);
class2.Class2Function();
}void class2\_Class2Event(object sender, EventArgs e) { // Respond to event here }
}
public class Class2
{
public event EventHandler Class2Event;public void Class2Function() { OnClass2Event(EventArgs.Empty); } protected virtual void OnClass2Event(EventArgs e) { EventHandler eh = Class2Event; if (eh != null) eh(this, e); }
}
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus)