Static event handler doesn't like forms
From: Tim Johnson (tjohnson_at_high-point.com)
Date: 10/16/04
- Next message: Tim Johnson: "Re: MessageWindow question"
- Previous message: Mike: "Re: .net cf sp2 problem"
- Next in thread: Robert Levy [MS]: "Re: Static event handler doesn't like forms"
- Reply: Robert Levy [MS]: "Re: Static event handler doesn't like forms"
- Reply: Alex Feinman [MVP]: "Re: Static event handler doesn't like forms"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 16 Oct 2004 12:25:03 -0700
I set up a custom event which I fire from another class upon certain extenal
circumstances, but in my form's event handler that catches the event I can't
reference my form controls:
The firing class looks like this:
public class MyStuff
{
public delegate void MyHandler(MyObject x);
public static event MyHandler MyEvent;
...
//Later fire the event as needed
MyEvent(myobjectx);
}
Over in a form I set up the handler like this:
public class MyForm : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox mylist;
private MyForm_Load(...)
{
MyStuff.MyEvent += new MyStuff.MyHandler(OnMyEvent);
}
public static void OnMyEvent(MyObject x)
{
mylist.Items.Add("Got here"); //Compiler fails on this line
}
}
This won't compile, complaining about the reference to mylist with
"MyForm.mylist denotes a 'field' where a 'class' was expected". If I
comment it out I can get to the handler just fine in the debugger at runtime
and my data looks good. I just can't use my form's controls.
I think this might be because the OnMyEvent method is static (which I think
it has to be to be an eventhandler), even though it's part of the MyStuff
formclass? Obviously if I get an event in my form I'd like to use it in my
form controls! How do I do it? I tried "this.mylist.Items.Add" but it
doesn't like that either.
-- Tim Johnson High Point Software www.high-point.com (503) 312-8625
- Next message: Tim Johnson: "Re: MessageWindow question"
- Previous message: Mike: "Re: .net cf sp2 problem"
- Next in thread: Robert Levy [MS]: "Re: Static event handler doesn't like forms"
- Reply: Robert Levy [MS]: "Re: Static event handler doesn't like forms"
- Reply: Alex Feinman [MVP]: "Re: Static event handler doesn't like forms"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|