我正在检查我的代码并重做所有事件,以便它们符合本文的要求,但我遇到了障碍。这是我的代码:
脚本.cs
public EventHandler<ScriptEvent> Load;
protected virtual void OnLoad(string file)
{
EventHandler<ScriptEvent> handler = Load;
if(Load != null)
Load(this, new ScriptEvent(file));
}
和脚本事件:
脚本事件.cs
public class ScriptEvent : EventArgs
{
private string m_File;
public string File
{
get { return m_File; }
}
public ScriptEvent(string file)
{
this.m_File = file;
}
}
问题是我无法弄清楚如何制作它,以便我的表单可以处理事件。例如,在 Script.cs 中加载了一个文件,然后当调用 Script.cs 中的 OnLoad(...) 时,表单会显示该文件。如果这令人困惑:
1) Script.cs 加载一个文件并触发 OnLoad(file)
2) Form1 接上 OnLoad 并做任何事情。
我认为这与我之前的做法类似(script.OnLoad += script_OnLoad(...)),但我很难过。