Release rectangle from being a parent at run time (in code)

At the moment I have quite a few controls that are children of an IDE drawn rectangle. So far this has worked great. I’m able to position the controls within, then move the rectangle, and all moves with it, as it should.

The rectangle was only ever meant to be a “placeholder” for visual and positional purposes. Now I’ve reached the point in my program where it needs to be replaced by a bitmap image which will be drawn underneath on the main window in the paint event using PixmapShape - along with a few other images that are already there.

I’m hoping that somehow in code, I can “un-parent” the rectangle, make it invisible (but not the controls within) and therefore show the image underneath and retain the rectangle for it’s positioning purposes for the IDE only.

Is this doable?


From the documentation (e.g. PushButton or RectControl):


The following example sets the parent of the control to the window.
Me.Parent = Nil[/quote]

So why don’t you read the documentation???

Mostly I do read the documentation Markus - and also search the forum. That’s why I haven’t posted a question on this forum for the last few weeks or so. Everything with my software is coming along just great, but unfortunately sometimes you have to interact with the humans. Also, I was being lazy. Sorry.

When you do program then you should have the documentation open too. First thing to do when having a question about the parent property is to look at the documentation for that property. I have a VERY bad memory, so I flick backwards and forward between the IDE and the documentation all the time. Quite often the documentation also gives me ideas on how to do things better. That being said I still use the old documentation as I absolutely hate the new one.

@Steve Kelepouris - Or just ask on the forum like you did. It’s what it’s here for and some kind samaratin is bound to answer your question. :slight_smile:

I usually just goggle “Xojo My Question” and come to the documentation or this forum.

So I tried in the Open Event of the rectangle:

Me.Parent = Nil Me.Visible = False

The rectangle and all the controls within disappear.

You need to set the parent of the controls within the rectangle to nil.

Ahhh, thanks Greg - that was my next thought.

I was looking at it as Me.Parent = Nil, means that I’m not a parent of the controls within. Whereas it really means, I don’t have a parent, and therefore needs to be set for all the controls within.

Fair bit of work to do then. I assume then that Me.Parent = Nil is to be put in the open event of all the child controls?

You could do something like this in the Open event of the window…

for i as integer = 0 to self.ControlCount-1 dim c as Control = self.Control(i) if c = rectangle1 then Continue if c isa RectControl then dim rc as RectControl = RectControl(c) if rc.Parent = rectangle1 then rc.Parent = nil end if end if next
I’ve written this to be rather verbose so it’s clear what’s going on. Rectangle1 being the name of your Rectangle control.

Well now that’s indeed getting into the “nitty gritty” of it all :).

So when you say the Open event of the window, you mean the window that contains all the controls - my rectangle1 and any other controls.

Your code then interrogates “all” the controls within that window, and if they are a child of my rectangle1 then they are released, ie. rc.Parent = Nil. Much quicker than individual code for each control.

I think I get it. It’s getting late here now, I’ll check back and test tomorrow.

Much thanks.

Thanks so much Greg.

Your code works perfectly. In my view it’s really a quite powerful piece of code. I did do some reading ie. Parent = Nil, ControlCount and RectControl and then made an effort to understand your code, I do get it mostly. Just wanted to let it be known that I didn’t just cut & paste.

I would have been blundering around for who knows how long and just ended up manually doing it. I can see potential in using this method - always.

To infinity and beyond! Cheers. :slight_smile:

[EDIT] And thank you for being verbose!