How to handle Window.Close() from a container control?

So I’m developing an app that has a “header” on every window that has the title of the page (passed when the window is opened) and a “close” button. I drag and drop it onto the top of every window. Now, I want to be able to click the close button and have it close the current window. I tried this in the Action() event:

Parent.Parent.Close()

Thinking that the parent for the button was the container but the parent of its parent was the window. That crashes the app. So I thought Parent.Close. As expected, that closed the container control but the window was still open.

How can I close the window that the container is part of when I click the close button on the container?

Windows already have this neat thing attached to them that shows a title by the way :wink:

http://documentation.xojo.com/index.php/RectControl.TrueWindow Will help you.

Why not add an event definition to that container control - say “DoClose”
Then on each page that has one of these containers you can implement that event however you need for that specific window

[quote=308700:@Norman Palardy]Why not add an event definition to that container control - say “DoClose”
Then on each page that has one of these containers you can implement that event however you need for that specific window[/quote]

I could do that. But I want to keep this as simple as possible as the person who may end up maintaining this app is basically learning to code as he goes.

[quote=308699:@Tim Parnell]Windows already have this neat thing attached to them that shows a title by the way :wink:

http://documentation.xojo.com/index.php/RectControl.TrueWindow Will help you.[/quote]

How the heck have I missed this all this time?!? Thank you! You just changed my freaking life lol.

You should encourage that person to do things the right way

Reaching out to true window and closing it is possible - and hacky

why is it hacky?

I don’t know about hacky, but it encourages spaghetti code, that’s for sure.

Adding an event to the container makes that container more reusable and provide a decent API
It lets the Window decide whether it should / should not close on a case by case basis rather than something you’ve added to the window deciding it for you. You get a surprising result (the window closing) for a completely non-obvious reason (you added a container control to the layout) That decision is IMHO in the wrong place

Being able to reference the containing window to determine metrics etc isn’t a bad thing
But put control of actions like this where they belong

Not doing things in a clear way means that any newcomer to that code will have a hard time figuring out why the Window closes because there’ nothing obvious ON the window that says “close” - it will be in code in the container control class

Its a less than clear way to design things at the very least
I’d call it a hack