0
我確實有一個用於日常監控的項目,我從我的文本框中獲取文本的問題,其中我的文本框位於我的用戶控件中。VB.net如何從我的用戶控件文本框中獲取價值
如果我點擊顯示按鈕,userControl.vb將在我的面板中調用,並且我沒有問題把userControl.vb放到我的面板上,如果我點擊保存按鈕,它將檢查是否所有字段在保存數據前都已填滿。我會保存爲正常,不會檢查我的面板,我打開了我的userControl.vb
這是我的片斷項目樹:
DXApplication
|_My Porject
|_User Control <folder>
|_userControl.vb <user control form>
|_frmMainActivity <winForm>
這裏是我爲我的面板中加載用戶控件代碼
Friend ctrlUser As UserControl
ctrlUser = New userControlx
ctrlUser.Dock = DockStyle.Top
pnlActivity.Controls.Clear()
pnlActivity.Controls.Add(ctrlUser)
這裏是代碼從另一個子從userControl調用文本框來檢查代碼是否可以獲取文本。
*edited the userControl should be userControlx*
Dim uc As New userControlx
Msgbox(uc.txtLatitude.text)
當我點擊觸發按鈕來顯示我放在我的文本框中的文本我會返回msgbox與空字符串。
有什麼建議嗎?在調用文本框的值時出錯了?
我已經嘗試使用:
Dim uc As New userControlx
uc.txtLongitude.text = "Test Text"
msgbox(ux.txtLongitude.txt)
它將返回測試文本,但在我的UI加載的文本框爲空。
在您創建的userControl
一個新實例觸發按鈕
UC是創建用戶控制的新實例。你不應該試圖檢查ctrlUser中的值嗎? –