2012-09-10 38 views
3

我想在MyObject來的類定義進行C#通過這個集裝箱引用類的構造函數

this.Controls.Add(MyObject) 

public MyClass(container/*?*/ con,Point L) 
{ 
con.Controls.Add(this); 
} 

我可以做這樣的事情? 謝謝。

+2

這是爲winforms/wpf/silverlight/asp /以上都不是? – Servy

+0

這是用於c#中的Windows窗體應用程序。我想用某些圖像創建「檢查點」(pictureboxes) – void

+1

什麼是MyClass?來源於...? –

回答

1

Control將工作得很好。

public void method(Control container) 
{ 
    container.Controls.Add(this); 
} 

如果您在Control不能真正有孩子(比如,TextBox)通過它要麼什麼都不做或在運行時拋出異常。

+0

是的,就是這樣,謝謝! – void