Hello,
I have a class derived from a windows forms control and implemented a new
event. Everything works fine within the class. But if I try to check the
event in the parent form I got nothing.
Any idea
Tia.
Torsten
public class NewListView : ListView
{
const int WM_VSCROLL = 0x0115;
public event EventHandler VScroll;
public NewListView()
{
this.VScroll += new EventHandler(OnVScroll);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_VSCROLL)
{
OnVScroll(this, new EventArgs());
}
base.WndProc (ref m);
}
public void OnVScroll(object sender, EventArgs e)
{
Console.WriteLine("Base: OnVScroll");
}
}
in parent form:
public class FormTest : System.Windows.Forms.Form
{
....
public FormTest()
{
this.newListView.VScroll += new EventHandler(this.newListView_VScroll);
}
....
private void newListView_VScroll(object sender, System.EventArgs e)
{
Console.WriteLine("VScroll");
}
....
}
Andrew Smith \(Infragistics\) - 20 Feb 2005 19:32 GMT
Unless I'm missing something, you're never raising the event. You're
OnVScroll in the listview should be something like:
protected virtual void OnVScroll(EventArgs e)
{
if (this.VScroll != null)
this.VScroll(this, e)
}
BTW, instead of creating a new eventargs (since it is not a derived
eventargs class), just pass EventArgs.Empty.
e.g.
if (m.Msg == WM_VSCROLL)
this.OnVScroll(EventArgs.Empty);
> Hello,
>
[quoted text clipped - 51 lines]
> ....
> }