G
Guest
Platform: WinCE 4.2, C#
I am working on a kiosk application where I have a System.Windows.Forms.Form
that contains a System.Windows.Forms.Panel derived class named HostPanel.
This panel in turn contains a System.Windows.Forms.Panel derived class named
ChildPanel. (For this example I have simplified the naming)
What I want to do is have the ChildPanel fire an event - when it has
completed its work - that the parent, HostPanel will catch and handle.
I am having trouble getting it to compile. I get the following compiler error:
"The event 'HostPanel.ChildButtonEvent' can only appear on the left hand
side of += or -= (except when used from within the type 'ChildPanel')"
Here is a simplified example of the code I am using:
class HostPanel : Panel
{
public delegate void ChildDoneEventHandler(object sender, EventArgs e);
public event ChildDoneEventHandler ChildDoneEvent;
HostPanel host;
Button btn;
ChildPanel child;
HostPanel()
{
this.ChildDoneEvent += new
ChildDoneEventHandler(HostPanel_ChildDoneEvent);
}
private void HostPanel_ChildDoneEvent(object sender, EventArgs e)
{
// Handle the child panel's event here.
}
class ChildPanel : Panel
{
HostPanel host;
Button btn;
ChildPanel(HostPanel pnl)
{
this.host = pnl;
this.Parent = pnl;
btn = new Button();
/// set all button properties.
btn.Click += new new System.EventHandler(this.btn_Click);
}
private void btn_Click(object sender, System.EventArgs e)
{
/// ERROR here:
/// "The event 'HostPanel.ChildButtonEvent' can only appear on the left
hand side of += or -= (except when used from within the type 'ChildPanel')"
this.host.ButtonEvent(sender,e);
}
}
I tried to declare the delegate and event outside of both classed but the
compiler will not allow events declared outside of classes.
Any ideas would be greatly appreciated.
TIA,
Mark
I am working on a kiosk application where I have a System.Windows.Forms.Form
that contains a System.Windows.Forms.Panel derived class named HostPanel.
This panel in turn contains a System.Windows.Forms.Panel derived class named
ChildPanel. (For this example I have simplified the naming)
What I want to do is have the ChildPanel fire an event - when it has
completed its work - that the parent, HostPanel will catch and handle.
I am having trouble getting it to compile. I get the following compiler error:
"The event 'HostPanel.ChildButtonEvent' can only appear on the left hand
side of += or -= (except when used from within the type 'ChildPanel')"
Here is a simplified example of the code I am using:
class HostPanel : Panel
{
public delegate void ChildDoneEventHandler(object sender, EventArgs e);
public event ChildDoneEventHandler ChildDoneEvent;
HostPanel host;
Button btn;
ChildPanel child;
HostPanel()
{
this.ChildDoneEvent += new
ChildDoneEventHandler(HostPanel_ChildDoneEvent);
}
private void HostPanel_ChildDoneEvent(object sender, EventArgs e)
{
// Handle the child panel's event here.
}
class ChildPanel : Panel
{
HostPanel host;
Button btn;
ChildPanel(HostPanel pnl)
{
this.host = pnl;
this.Parent = pnl;
btn = new Button();
/// set all button properties.
btn.Click += new new System.EventHandler(this.btn_Click);
}
private void btn_Click(object sender, System.EventArgs e)
{
/// ERROR here:
/// "The event 'HostPanel.ChildButtonEvent' can only appear on the left
hand side of += or -= (except when used from within the type 'ChildPanel')"
this.host.ButtonEvent(sender,e);
}
}
I tried to declare the delegate and event outside of both classed but the
compiler will not allow events declared outside of classes.
Any ideas would be greatly appreciated.
TIA,
Mark