2010-02-26 119 views
2

嗨我已經設置了幾個子窗體都從一個根窗體,設置幾個按鈕和標誌等,然後過濾到孩子。 我用Visual Studio的嚮導添加子窗體從根繼承和它們與自動聲明:C#根窗體繼承,更改導致破碎的子窗體

public partial class WelcomeForm : MynetInstaller.rootForm 

現在我已經被要求調整子窗體和移動按鈕,事情我希望會做通過簡單地更改根形式並允許更改過濾。

我的兩個問題是: 1 /我改變了大小,這根本不影響孩子,似乎在初始設置後大小沒有被繼承。

2 /我改變按鈕的位置,這將導致所有子窗體突破錶明一個錯誤:

To prevent possible data loss before loading the designer, the following errors must be  resolved: 



'child' is not a child control of this parent.  

Instances of this error (1) 

1. Hide Call Stack 

at System.Windows.Forms.Control.ControlCollection.GetChildIndex(Control child, Boolean  throwException) 
at System.Windows.Forms.Control.ControlCollection.SetChildIndexInternal(Control child, Int32 newIndex) 
at System.Windows.Forms.Control.ControlCollection.SetChildIndex(Control child, Int32 newIndex) 
at System.Windows.Forms.Design.ControlDesigner.DesignerControlCollection.SetChildIndex(Control child, Int32 newIndex) 

如果我按下去會加載頁面,但不會有移動的按鈕,如果我嘗試並運行它我得到一個錯誤:

this.Controls.SetChildIndex(this.btnNext, 0); 

說:

'child' is not a child control 

我諾蒂奇編輯,當我移動控制它停止成爲鎖定,但手動改變這並沒有幫助。

回答

2

基本形式的大小繼承,設計師通常會阻止再次在派生形式中設置大小。但可能會發生意外,子表單可能會被巧妙地改動一次。或者,它可能是在設計了基本形狀的機器上具有不同視頻DPI設置的機器上設計的。

對於這個我只能想到,編輯設計器生成的代碼只有解決方法。在解決方案資源管理器窗口中,打開子窗體旁邊的節點,然後雙擊Designer.cs文件。展開標有「Windows窗體設計器生成的代碼」的區域,並找到ClientSize屬性的分配。刪除它。

不知道你的第二個問題是怎麼回事,這不是一個正常的問題。看看操作按鈕時設計器生成的代碼會發生什麼。

0

對於「'孩子'不是孩子控制」問題,您必須從.designer.cs文件.setChildIndex命令行中刪除該問題。

+0

在我繼承的表單控件位置發生變化時。我解決了這個問題。我從.designer.cs文件中移除「this.AutoScaleDimensions = new System.Drawing.SizeF(6F,13F);」線。 – 2015-06-18 07:46:10