How to call method in parent?

  • Thread starter Thread starter Fister
  • Start date Start date
F

Fister

Hi

I'm trying to call a method in a parent control from the child control but
I get this error:

'System.Windows.Forms.Control' does not contain a definition for 'doSomething'

What am I doing wrong?


public partial class ParentControl : UserControl
{
private ChildControl childControl;

public ParentControl()
{
InitializeComponent();

childControl = new ChildControl();
childControl.Width = 32;
childControl.Height = 32;
childControl.Location = new Point(10, 10);
childControl.Parent = this;
Controls.Add(childControl);
}

public void doSomething()
{
...
}
}

---

public partial class ChildControl : UserControl
{
private void ChildControl_Click(object sender, EventArgs e)
{
this.Parent.doSomething();
}
 
Back
Top