3

In .net Compact Framework 2.0, you could add a form to another forms control array basically parenting the other form.

i.e._mainForm.Controls.Add(form);

This is not allowed in .net cf 3.5 and results in an exception:

System.ArgumentException: Value does not fall within the expected range. at Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR ar) at System.Windows.Forms.Control._SetParent(Control ctlParent) at System.Windows.Forms.Control.set_Parent(Control value)

Is there a workaround or alternative for this? I need to be able to parent a form inside a panel on another form.

JoelHess
  • 1,166
  • 2
  • 15
  • 28

2 Answers2

5

I think this contains answer to your question: http://207.46.16.248/en-us/netframework/bb986636.aspx

especially this part:

System.Windows.Forms.Form.Parent

Description Forms can no longer be parented.

Previous Behavior
In .NET Compact Framework 1.0, forms could be parented to any other control that supported child controls. In .NET Compact Framework 2.0, forms could be parented to any other form.

New Behavior

In the .NET Compact Framework version 3.5, forms cannot be parented.

grapkulec
  • 1,022
  • 13
  • 28
  • I came across this. I'm hoping to find a workaround or an alternative method. – JoelHess Jul 12 '11 at 01:05
  • 2
    well, why you need your form to be parented? it was some time ago when I was dealing with CF 3.5 but I don't recall any problems with forms in my app that I needed to do any explicit magic with my forms – grapkulec Jul 12 '11 at 06:22
  • It's the existing architecture of the system. I'm not looking to redo the system, but in maintaining it wanted to use some linq-y goodness. – JoelHess Jul 13 '11 at 18:35
  • so you need LINQ on .net 2.0? maybe these links will help you: http://stackoverflow.com/questions/2138/linq-on-the-net-2-0-runtime, http://weblogs.asp.net/fmarguerie/archive/2007/09/05/linq-support-on-net-2-0.aspx but I think these are rather abount full framework version not compact. – grapkulec Jul 13 '11 at 19:34
  • or, if you have actual requirement to use LINQ, you will talk to whoever is decision maker in your company/project and explain to him/her/them that LINQ is basically .net 3.5 stuff and without moving whole or at least parts of a system into new framework version it will be rather hellish task to accomplish. – grapkulec Jul 13 '11 at 19:37
0

You can use the following method to copy form controls to another form in .NET CF 3.5

// Clear old form controls

oldform.Controls.Clear();

// Copy controls from newform to oldform

foreach (Control ctl in newform.Controls)
{
    oldform.Controls.Add(ctl);
}
Rob Hruska
  • 118,520
  • 32
  • 167
  • 192