如何从表单访问用户控件的文本框? [英] How to access user controls' text box from a form?

查看:69
本文介绍了如何从表单访问用户控件的文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些代码来自frmBillingPatient ..



我的问题是当我在patientListView中选择一行时我无法将其放入lbl尝试frmBillingManagement,它无效。但它与frmMain合作。



注:

frmBillingManagement是一个用户控件

frmMain是一个表单



谢谢!



我的尝试:



Those code are from frmBillingPatient..

my problem is when I select a row in patientListView i cant put it into the lblTry in frmBillingManagement, its not working. But its working with the frmMain.

Note:
frmBillingManagement is a user control
frmMain is a form

thanks!

What I have tried:

Public Sub patientListView_MouseClick(sender As Object, e As MouseEventArgs) Handles patientListView.MouseClick
patientID = patientListView.FocusedItem.SubItems(1).Text
frmMain.Label1.Text = patientID.ToString
frmBillingManagement.lblTry.Text = patientID.ToString
frmBillingManagement.Refresh()
frmBillingManagement.lblTry.Refresh()
Me.Close()
End Sub

推荐答案

VB.NET提供Windows窗体应用程序中每个表单的默认实例,主要是为了与VB6向后兼容。



My.Forms和My.WebServices(Visual Basic)提供的默认对象实例 [ ^ ]

< a href =https://msdn.microsoft.com/en-us/library/87y2hdsf.aspx> My.Forms对象 [ ^ ]

在Visual Basic .NET中使用多个表单:升级到.NET [ ^ ]



所以,当你引用 frmMain。某事 时,你实际上是指类的默认实例frmMain



用户控件的也是如此。没有包含表单的用户控件的实例没有用处。由于控件可以在多种不同的表单上多次使用,因此没有合理的方法来选择单个默认实例。



相反,用户控件将在包含表单上显示为(一个或多个)成员。控件的每个实例都会分配一个ID,您可以使用设计视图进行更改。



因此,如果您的控件实例位于当前表单上,则ID为 billingManagement1 ,您将使用:

VB.NET provides a default instance of each form in a Windows Forms application, primarily for backwards-compatibility with VB6.

Default Object Instances Provided by My.Forms and My.WebServices (Visual Basic)[^]
My.Forms Object[^]
Working with Multiple Forms in Visual Basic .NET: Upgrading to .NET[^]

So, when you reference frmMain.something, you're actually referring to the default instance of the class frmMain.

The same is not done for user controls. An instance of a user control without a containing form would serve no purpose. And since the control could be used multiple times on multiple different forms, there would be no sensible way to pick a single "default" instance.

Instead, the user control will be exposed as (one or more) members on the containing form. Each instance of the control will have an ID assigned, which you can change using the design view.

So, if your control instance is on the current form, with an ID of billingManagement1, you'd use:
billingManagement1.lblTry.Text = patientID.ToString()



如果它在 frmMain


If it was on frmMain:

frmMain.billingManagement1.lblTry.Text = patientID.ToString()


这篇关于如何从表单访问用户控件的文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆