C# 无法访问要在HandlerRequest中使用的EventArgs e值
我只是在学习活动、代表和订阅者。在过去的两天里,我一直在研究和思考这一切。我无法访问在我的EventArgs e值中传递的信息。我有一个保存的项目要打开。必要表单的状态被反序列化到字典中。将命中一个循环,该循环将引发解包请求,并将键/值与其一起传递 ProjectManager.cs文件:C# 无法访问要在HandlerRequest中使用的EventArgs e值,c#,events,eventargs,C#,Events,Eventargs,我只是在学习活动、代表和订阅者。在过去的两天里,我一直在研究和思考这一切。我无法访问在我的EventArgs e值中传递的信息。我有一个保存的项目要打开。必要表单的状态被反序列化到字典中。将命中一个循环,该循环将引发解包请求,并将键/值与其一起传递 ProjectManager.cs文件: public delegate void EventHandler<TArgs>(object sender, TArgs args) where TArgs : EventArgs; publi
public delegate void EventHandler<TArgs>(object sender, TArgs args) where TArgs : EventArgs;
public event EventHandler<UnpackEventArgs> UnpackRequest;
//Raise a UnpackEvent //took out virtual
protected void RaiseUnpackRequest(string key, object value)
{
if (UnpackRequest != null) //something has been added to the list?
{
UnpackEventArgs e = new UnpackEventArgs(key, value);
UnpackRequest(this, e);
}
}
foreach (var pair in dictPackState) {
string _key = pair.Key;
dictUnpackedState[_key] = dictPackState[_key];
RaiseUnpackRequest(pair.Key, pair.Value); //raises the event.
}
然后在open方法中,在用每个表单的状态填充dictionary之后:
ProjectManager.cs文件:
public delegate void EventHandler<TArgs>(object sender, TArgs args) where TArgs : EventArgs;
public event EventHandler<UnpackEventArgs> UnpackRequest;
//Raise a UnpackEvent //took out virtual
protected void RaiseUnpackRequest(string key, object value)
{
if (UnpackRequest != null) //something has been added to the list?
{
UnpackEventArgs e = new UnpackEventArgs(key, value);
UnpackRequest(this, e);
}
}
foreach (var pair in dictPackState) {
string _key = pair.Key;
dictUnpackedState[_key] = dictPackState[_key];
RaiseUnpackRequest(pair.Key, pair.Value); //raises the event.
}
我有一节课要上:
public class UnpackEventArgs : EventArgs
{
private string strKey;
private object objValue;
public UnpackEventArgs(string key, object value)
{
this.strKey = key;
this.objValue = value;
}
//Public property to read the key/value ..and get them out
public string Key
{
get { return strKey; }
}
public object Value
{
get { return objValue; }
}
}
我仍在编写代码来添加订阅者,以及如何在各个表单中重新构建项目组件。但是我现在尝试处理的部分是MainForm.cs,在这里我使用获得通过的参数处理未打包的请求。My e包含键值,键值表示将值发送到何处(即表单对象)
我想我包括了所有需要帮助的部分?!谢谢 改变这一点:
private void HandleUnpackRequest(object sender, EventArgs e)
为此:
private void HandleUnpackRequest(object sender, UnpackEventArgs e)
记住您的事件处理程序声明:
public event EventHandler<UnpackEventArgs> UnpackRequest;
公共事件事件处理程序请求;
更改此选项:
private void HandleUnpackRequest(object sender, EventArgs e)
为此:
private void HandleUnpackRequest(object sender, UnpackEventArgs e)
记住您的事件处理程序声明:
public event EventHandler<UnpackEventArgs> UnpackRequest;
公共事件事件处理程序请求;
非常感谢您!!成功了!酷。标记为“已回答”。非常感谢!!成功了!酷。将其标记为“已回答”。