2016-01-22 22 views
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一个新实例触发按钮
+0

UC是创建用户控制的新实例。你不应该试图检查ctrlUser中的值吗? –

回答

0

,这就是为什么你的文本框的内容不能为空

改用

Msgbox(ctrlUser.txtLatitude.text) 
相关问题