M
mp
I'm trying to digest the basic event syntax(and not succeeding very
well<g>)
************************************************
according to page: http://www.codeproject.com/KB/cs/event_fundamentals.aspx
one should, if possible, use the generic framework supplied objects
System.EventArgs
"You can encapsulate all event arguments as properties
of a class that derives from System.EventArgs."
"The first alternative listed above is strongly encouraged,
and support for it is built into the .NET Framework
through the System.EventArgs class."
--and--
"While you can create your own event handlers (and sometimes you might need
to),
you should use one of the EventHandler delegates provided by the .NET
Framework
in cases where one of the Framework's event handlers would work
with your particular event implementation. "
************************************************
i'm trying here to create the absolute simplest format so i can begin
understanding
where am I going wrong in the following simple form
button_click wants to raise an event that carries no data (so
System.EventArgs.Empty)
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public delegate void EventHandler(object sender, EventArgs e);
public event EventHandler MyEvent;
public class MyEventArgs : System.EventArgs
{ }
public void RaiseTheEvent(MyEventArgs eventArgs)
{
try
{
EventHandler handler = MyEvent;
if (handler != null)
{
handler(this, eventArgs);
}
}
catch
{
// Handle exceptions here
}
}
private void button1_Click(object sender, EventArgs e)
{
RaiseTheEvent(MyEventArgs.Empty);
}
}
}
....useless whining follows...
vb6 took one line to define an event, one line to raise it, and one line to
catch it!?!
c# makes me feel sooooo dumb!!!
:-/
mark
well<g>)
************************************************
according to page: http://www.codeproject.com/KB/cs/event_fundamentals.aspx
one should, if possible, use the generic framework supplied objects
System.EventArgs
"You can encapsulate all event arguments as properties
of a class that derives from System.EventArgs."
"The first alternative listed above is strongly encouraged,
and support for it is built into the .NET Framework
through the System.EventArgs class."
--and--
"While you can create your own event handlers (and sometimes you might need
to),
you should use one of the EventHandler delegates provided by the .NET
Framework
in cases where one of the Framework's event handlers would work
with your particular event implementation. "
************************************************
i'm trying here to create the absolute simplest format so i can begin
understanding
where am I going wrong in the following simple form
button_click wants to raise an event that carries no data (so
System.EventArgs.Empty)
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public delegate void EventHandler(object sender, EventArgs e);
public event EventHandler MyEvent;
public class MyEventArgs : System.EventArgs
{ }
public void RaiseTheEvent(MyEventArgs eventArgs)
{
try
{
EventHandler handler = MyEvent;
if (handler != null)
{
handler(this, eventArgs);
}
}
catch
{
// Handle exceptions here
}
}
private void button1_Click(object sender, EventArgs e)
{
RaiseTheEvent(MyEventArgs.Empty);
}
}
}
....useless whining follows...
vb6 took one line to define an event, one line to raise it, and one line to
catch it!?!
c# makes me feel sooooo dumb!!!
:-/
mark