I'm working on an application so i have write an dll which contain a form with some additional work and methods. so in the beginning of my program the thread launch this form (from my dll) to get some informations and then hide it and initialize some components and the application form and then show it. when the thread come the line where it define new instance of the exported form
"MyForm inputform = new MyForm();"
it throw an Exception called "Top-level control cannot be added to a control." so i don't know what to do ?!!. i tried to take the code of the form from the dll source code and put it in the main program and it works.... .but still i want to know what happen and what impede my application from run that form from my开发者_如何学运维 dll. thanks.
The line that raises the error is possibly not the line you show above, but likely one of the lines that follows it. I.e., if you have something like the following:
currentControl.Controls.Add(inputForm);
it will not work and raise the error you mention.
Instead, use inputForm.Show(ownerForm)
to show the form when you want it and you should be fine. A form (a top level control) cannot be added to a normal control, like a panel, a textbox or a picturebox.
Note: if the line in your post does raise the error, then inside the form initialization code lies a piece of code that raises the error, check there
精彩评论