How do I parent a new window to the current GH document?

How do I parent a new window to the current GH document, such that it opens centered on the document, and closes when the document is closed (in C#)?

This is what I have right now, but it doesn’t close the window when the document, or even Grasshopper is closed (I assume because Grasshopper is just hidden):

if (_window == null || _window.IsDisposed)
{
    _window = new Window(this);

}

var owner = Grasshopper.Instances.DocumentEditor;
GH_WindowsFormUtil.CenterFormOnWindow(_opossumWindow, owner, true);
_window.Show(owner);

Correct, Grasshopper is hidden, not closed unless the GrasshopperUnloadPlugin command is invoked.

The Grasshopper document editor has a FormShepard associated with it and you can register your form with the shepard. It will automatically move your window along with Grasshopper, and also synchronise the hide/show.

1 Like

Thanks David! That’s what I needed!

Another minor thing:
CenterFormOnWindow doesn’t seem to do anything.
The Form always opens in the upper left of the screen, which is fine, I’m just wondering why this line doesn’t seem to have any effect.

var owner = Grasshopper.Instances.DocumentEditor;

if (_window == null || _window.IsDisposed)
{
    _window = new Window(this);
    owner.FormShepard.RegisterForm(_opossumWindow);
}

GH_WindowsFormUtil.CenterFormOnWindow(_opossumWindow, owner, true);
_window.Show(owner);

I think CenterFormOnWindow method can only work if the Form.StartPosition property is set to FormStartPosition.Manual

1 Like

That did it! Thanks!