Adding Forms to TabPages

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Ok, so I have a VS2003 CF project that I converted to VS2005 CF v2.0. In the
original version I had a TabControl with TabPages that I would add Forms to
as follows and it worked great;

MyTestForm myForm = new MyTestForm();
tabPage1.Controls.Add(myForm);

In VS2005 the identical code throws an ArgumentException of “Value does not
fall within the expected rangeâ€. This doesn’t make sense to me since Form
derives from Control; it seems that it meets the criteria for adding to a
ControlCollection.

Another news groupie asked this same question on 12/5/2005 & got a reply to
the effect that Microsoft hadn’t planned for you to do that so don’t do it. I
was hoping someone out there could provide a more satisfying answer, since it
is very convenient to use the amenities of the Form such as the load event.
Naturally, I would also like to avoid the overhead of developing a workaround
and implementing it if there is a reasonable way to make Forms work. (After
all, VS2005 was supposed to save us time… right?)

Bill
 
You have to use a UserControl instead.

If you think about it, that makes more sense that using a form in a
tabcontrol. IMO, the fact that it works in CF v1.0 is either a bug or a
relaxation given the absense of the UserControl class in v1.0

Cheers
Daniel
 
Back
Top