views:

31

answers:

1

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.

+2  A: 

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

Abel
i checked the code's line of my application, then i run it WITHOUT any change. and suddenly, it works fine with no Exception. i really feel depressed about what happening i tried thousands times before i post the question and i didn't work. i don't know what happened, do u know ?
mavric