Closing containercontrol

Windows 10 / Xojo 2018r4

I have a ContainerControl ‘ccInputForm’
I add this container to a window in the ‘Open event handler’, with following code :

Dim cc As New ccInputForm
cc.EmbedWithin(self, 100, 100)

The window has a Button that I would like to use to close the ‘ccInputForm’
In the ‘Action event handler’ of the button i put the code :

cc.Close

But this ‘cc.Close’ gives an error. cc is seen as a int32.
cc is not recognized as containercontrol item.

What do I wrong ?
Has someone a solution ?
Reading the doc is not getting me any further.

Thanks
Regards
Etienne

“cc” is defined as a local variable that goes out of scope as soon as the event is complete, the compiler has no idea what “cc” is from the point of view of the button. Consider adding “cc” as a property of the window, remember to also remove the reference to the control by setting it to nil after closing the control.

Consider moving the Close button to the ccInputForm and adding to the button’s action event:

self. close

This would be fine if the cc only needs to appear once when the window opens. If you need to toggle it on and off later , you will need to do something along the lines of Alex’s suggestion.

[quote=493312:@Craig Hyde]Consider moving the Close button to the ccInputForm and adding to the button’s action event:

self. close

This would be fine if the cc only needs to appear once when the window opens. If you need to toggle it on and off later , you will need to do something along the lines of Alex’s suggestion.[/quote]

Most of the time I need the ContainerControl to “submit” data back to the parent window/control. In these cases, I will use a WeakRef so I can call methods or give the ContainerControl events that can be handled by the parent.

Thanks for the reply.
Both the solution work fine.
Momentary I use the close button in the containercontrol for closing the ‘ccInputForm’

May I askd another question concerning the ContainerControl.
Is it possible to pass some parameters that are needed within the ContainerControl.

Depending of what I need , the containercontrol should not always show the same controls (textfields, labels, popupmenus…)

Perhaps I ask something that is not possible ?

Thanks
Regards
Etienne

You need to implement the Constructor method for the cc and pass it parameters when you say:

Var cc As New ccInputForm (param1, param2, etc) cc.EmbedWithin (self, 100, 100)

The Constructor method is a method of the cc named Constructor. Give it the params you want it to have.

Tim, Alex, Craig,
Thanks for all these good replies. Great.
I like this forum. Always fast and good solutions for my problems.
I’ve learned nice new stuff today .

Regards
Etienne