I would definitely suggest you look into and become more experienced with using interfaces in your code. This will definitely help you solve the issue you’re running into right now. Your children, defined in Project A, should be able to interact with an interface that you implement in project B.
Let me try to create an example using what you have described so far…
Lets say you have defined Button, which inherits from Control, in one project…
public class Control { }
public class Button : Control { }
Then in another project, you’ve defined Form which stores a list of Controls. Then, in your game Initialize, you add a Button to it…
public class Form
{
public event EventHandler<EventArgs> FormResized;
public List<Control> Controls { get; private set; } = new List<Control>();
public void TriggerFormResized()
{
if (this.FormResized != null)
this.FormResized(this, new EventArgs());
}
}
public class MyGame : Game
{
private Form _form = new Form();
public Initialize()
{
_form.Controls.Add(new Button());
_form.TriggerResize();
}
}
If I’m reading you correctly, this is an example of where you’re at now. We’ve created a form that can trigger some kind of resize event, but Button can’t know about it because Form is defined in another project which cannot be referenced since the Form project already references the Button project.
This is where you can use an interface to define what is available on a Form. You’re effectively creating a contract where you’re saying “Hey, anybody who implements this interface… I don’t really care what other things you do, but you will at least provide these things.”
So, in the project that defines button (or some project below that in the hierarchy), we can define an interface for Form which says that it has an event on it, FormResized.
public interface IForm
{
event EventHandler<EventArgs> FormResized;
}
Now, we can give an instance of IForm to Button, so it can do things.
public class Button : Control
{
private IForm _parent;
public Button(IForm parent)
{
_parent = parent ?? throw new ArgumentNullException();
_parent.FormResized += (sender, e) => System.Diagnostics.Debug.WriteLine("Parent form has resized!");
}
}
Now, we just have Form inherit from the interface…
public class Form : IForm
{
// All the other stuff
}
Now, in the example game above, when we tell Form to trigger a resize event, button will know about it.
Obviously this is a contrived example, but hopefully you get what I mean