C# form needs to call method defined in parent form
.net, c#, oop
Solution
Use `protected` as the access modifier on your method as opposed to `private`.
`private` means only for the class that the method is contained within. `protected`, on the other hand, means the current class and all that inherit from it.
Your code will look like this:
public partial class MainForm: Form
{
protected bool SaveSomething()
{
// ...
}
}
This is called an Access Modifier, the link is to an MSDN article on all of the available access modifiers in C# (`public`, `private`, `protected`, `internal`, and `protected internal`).
Problem
I have a form (`EmployeeForm`) that inherits from a partial class form (`MainForm`). Inside `MainForm` I have a method (`SaveSomething`) that I want to call. How do I do this? ``` using SomeLib; namespace FooEmployee { public partial class EmployeeForm: MainForm { private void dgv_DoubleClick(object sender, EventArgs e) { SaveSomething(); } } } namespace SomeLib { public partial class MainForm: Form { private bool SaveSomething() { } } } ```