How to call method in parent?

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();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top