Closing an instance of a window

Hello !

let’s say a have a window called “MyWindow” with a Push Button on it…

I open this widow with:

dim myNewWindow as New MyWindow

now i would like that the button in myNewWindow closes his parent window
i have tried

Me.Parent.Close

and something else like that but had no luck …

Any hint??

Thanks :slight_smile:

When you instatiate myNewWindow it has no idea where it came from. You’ll need to pass that information to it, like in the constructor, and store it in a property that the PushButtons code can access.

To MyWindow add

[code]Private Property theParentWindow As Window

Sub Constructor(w As Window)
Super.Constructor
theParentWindow = w
End Sub

Sub Action() //PushButton event
theParentWindow.Close
End Sub[/code]

and now to create MyWindow pass in self as the parent

dim myNewWindow as New MyWindow(self)

thanks @stuart s !

If the button is on the window, you can just call

self.Close

or if it happens to be in a container control on a window

me.TrueWindow.Close

Sorry for not getting to you earlier @shao sean but didn’t get a notification for your reply.
Thanks a lot for your suggestion !