I have a program which creates new Controls (actually – Form‘s with TopLevel = false) and puts them on a Panel which is on Form1.
For some reason, this is usually followed by what seems like a Form appearing very briefly outside of Form1. It’s hard to tell exactly what’s happening because it’s so brief. Perhaps it’s Form1 moving there (and changing its size) and then returning. Or perhaps it’s the Form that’s being put on Form1 that appears there (though how could that happen at all? It’s out of Form1!).
I couldn’t find anything in the code that might cause it, and the whole code is way too long to post here. (The relevant code is simply: MyPanel.Controls.Add(newForm);.)
Is there any known bug that might cause this?
I can sort of guess what the code looks like. The problem with adding a Form to the Controls collection with TopLevel = false is that you have to explicitly make it visible. This is an odd quirk (aka bug), normally a control automatically becomes visible when you add it to a Controls collection.
So it probably looks like this:
And yes, that can make it visible for a very brief moment, still as a top-level window, if you do something else that causes messages to be dispatched. Fix it by swapping the Visible and TopLevel property assignments.
If this doesn’t help then post a code snippet.