tags:

views:

93

answers:

2

EDITED:

When I load a form dynamically inside another form or container control, the editing behaviour of all the form's components is different. Text editing, in a TextBox or ComboBox, does not allow me to select partial text with the mouse, though I can double click to select all the text in the control.

     FormChild form = new FormChild();
     form.TopLevel = false;
     form.Dock = DockStyle.Fill;
     Controls.Clear();
     Controls.Add(form);
     form.Show();

The controls work as expected when I show the form normally, using Show() or ShowDialog(), but not inside something.

The initial question was regarding a form inside a panel, but I've now removed the panel and tried loading the form inside the outer form, or any other container control.

NOTE: I'm getting a lot of comments about how "weird" this is. We've been embedding forms inside MFC controls using FormView for years, so I don't know why this is so weird to people. It is a common concept. In any case, saying it is weird isn't a solution.

EDIT: I should have used a User Control in the first place. Thanks guys.

+2  A: 

Is it possible to place all the functionality (including controls) in your form into a User Control? If you want this functionality in a separate form, drop the User Control into an empty form, if you want it as part of an existing form, drop it into that.

This isn't a solution to the problem as you presented it, but maybe this suggestion will help.

Jay Riggs
I had already designed all of the forms, then the customer requested I not show a new dialog, but to load it into a content area, so I went this route. I suppose it would be best to convert all of the forms to controls?
mrjoltcola
I don't know how many forms you're dealing with or their order of complexity, but you might consider at least testing this by taking your simplist form and converting it to a UC.
Jay Riggs
Done. Converting one of them to a control resolved the issue. Thanks for the suggestion. Time to get converting... :)
mrjoltcola
+1  A: 

Judging from what you have posted, you want to dynamically load some ui elements and only show them when all are done loading? I usually will do it with a `Panel' or user control

[not compile tested code]

Panel p = new Panel();
p.TopLevel = false;
p.Dock = DockStyle.Fill;
p.Controls.Add( button );
// etc
Controls.Clear();
Controls.Add(p);
BioBuckyBall
Thanks. I think I should have used a User control instead of a Form in the first place. I had already coded the forms when the customer requested they be put inside a content area, so I took the first route that occured to me. I'm no WinForms guru, this is the first time I'd tried this in WinForms, though I still don't understand the reason for the behaviour. The forms otherwise function well.
mrjoltcola
@mrjoltcola Ouch...hopefully not too many forms. You may be able to copy most of the code out of the *.designer.cs files
BioBuckyBall
+1 thanks for the suggestion. Converting the forms to controls seem to be the best route now.
mrjoltcola