开发者

Compact Framework 3.5 Set Form parent

开发者 https://www.devze.com 2023-03-19 06:34 出处:网络
In .net Compact Framework 2.0, you could add a form to another forms control array basically parenting the other form.

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 ra开发者_开发问答nge. 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.


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.


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消