Setting the parent of a form raises exception in NET CF 2.0

Hello,

I just ported an application from NET CF 1.0 to NET CF 2.0 (SP1) and I get the error

System.ArgumentException: Value does not fall within the expected range.
at Microsoft.AGL.Common.MISC.HandleAr()
at System.Windows.Forms.Control._SetParent()
at System.Windows.Forms.Control.set_Parent()
at com.incahellas.FormHelper.PrepareForm()
at com.incahellas.FormHelper.ShowForm()
at pocketerp.Form1.MainWorkA()
at pocketerp.Form1.set_Func()
at pocketerp.Form1.Form1_Load()
at System.Windows.Forms.Form.OnLoad()
at System.Windows.Forms.Form._SetVisibleNotify()
at System.Windows.Forms.Control.set_Visible()
at System.Windows.Forms.Application.Run()
at pocketerp.MainClass.Main()
}

whenever I try to set the parent of a form.

Does anybody know why this is happening



Answer this question

Setting the parent of a form raises exception in NET CF 2.0

  • Saad Kanawati

    I know that NETCF V1 would not ignore my attempt because it was the way I used to have a form with specific dimensions on Pocket PCs. As soon as the parent of the form was set to a panel the form was confined to the panel. Now if I set the parent to another form I can not achieve the same effect.

    For someone who was not using this behavior is not an unreasonable breaking change, but for me it sure is.


  • cbpd86

    I've seen reports of that if form is trying to set parent to itself.



  • preethi_rjs

    Unfortunately, this is not the case. I have a main form with a panel and I create other forms which are set as children of the panel. So I try to change the parent from null to my panel and I get this exception.

    I also created a new project in order to verify this behavior and I noticed that the parent of the form can be set only to another form or null. For me this is a bug, or an unreasonable breaking change.


  • Paashi

    The application is pretty complex and has about 15 child forms, which are placed on the panel of the main form.

    This has two advantages:

    a) Only the main form deals with the dimensions and orientation of the screen.

    b) It's the only way to use the Visual Studio Designer. I guess I could now use UserControl, but is there a way to convert the forms to usercontrols without redesigning everything from scratch


  • Blackwood

    That's right, form can't be a child of a panel because form is a top level control. Most likely NETCF V1 would just ignore your attempt to do that without actually setting anything and you had no clue your code did not work. Now it throws and you know your code is wrong and needs to be corrected. So it's not an "unreasonable breaking change", just corrected behavior and it’s matching desktop. Fix is simple in this case – set form’s parent to a form, not to a panel.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

    Note: it is a breaking change for your V1 application if executed against V2. However, version coercion would allow it to run.

     



  • Yelnik

    If you need that buggy behavior so much, you can launch your application in V1 compatibility mode. Alternatively stay with NETCF V1.

     

    Also keep in mind that probably violates design PPC guidelines (as forms should be full screen on PPC) so your application can never be certified as PPC compatible.

     

    By the way, why can’t you just get rid of second form and put whatever you have on it into the panel That should produce same look and feel, you won’t need to use undocumented buggy behavior and it won’t violate PPC design guidelines.



  • Setting the parent of a form raises exception in NET CF 2.0