0
我的程序包含一個空的TabControl。這可以通過,通過一個動作,可以添加到TabControl的自定義實例的用戶填入用戶控件我已經定義:指向UserControl實例的對象
myUserControl newInstance;
newInstance = new myUserControl();
myTabControl.TabPages.Add(newInstance);
這個對象myUserControl
不只是一個簡單的空TabPage
,但它包含了一些其他對象如textboxes
,comboboxes
和labels
。
例如,如何指向此新頁面的第一個文本框來更改其文本?我在想這個問題:
myTabControl.SelectedTab.textbox1.Text = "change the text";
但它不工作,因爲下面的錯誤,我不能編譯(我非常理解):
'System.Windows.Forms.TabPage' does not contain a definition for 'textbox1' and no extension method 'textbox1' accepting a first argument of type 'System.Windows.Forms.TabPage' could be found (are you missing a using directive or an assembly reference?)
我怎麼可以指向文本框是應該加入我添加的myUserControl
的實例嗎?
Hi @Sybren,我的方法有問題。使用'Instance'工作得很好,但只有最後一個實例。如果我需要檢索該類的以前的實例(例如修改我在最後一個之前創建的「myUserControl」實例的文本),我該如何管理? – 2014-10-13 11:50:16
如果您想回答,我已經打開了一個新線程[here](http://stackoverflow.com/questions/26340904/using-previous-instances-of-a-usercontrol)。 – 2014-10-13 13:17:08