简体   繁体   English

获取用户控件中的文本框值

[英]Get textbox value in user control

I'm anand.我是阿南德I have a problem about how to get text value in textbox in user control.我有一个关于如何在用户控件的文本框中获取文本值的问题。 I make a small application.我做了一个小应用。 I use Form1 as main form, and in the form I put one panel.我使用 Form1 作为主窗体,并在窗体中放置一个面板。 In panel I will put custom user control that contain textbox.在面板中,我将放置包含文本框的自定义用户控件。 Now, I want to get the text on the textbox in user control and show it in the msgbox.现在,我想获取用户控件中文本框上的文本并将其显示在 msgbox 中。 Can anyone help me to fix this problem please?任何人都可以帮我解决这个问题吗?

As André Leal said in the comments.正如安德烈·莱尔 (André Leal) 在评论中所说。 If you define a public property in your user control you will be able to access the value.如果您在用户控件中定义公共属性,您将能够访问该值。

Public Property textboxValue as String
     Get
          Return MyTextBox.text
     End Get
     Set(value as String)
          MyTextBox.text = value
     End Set
End Property

Then you can access it using code like this.然后你可以使用这样的代码访问它。

YourUserControl.textboxValue

If you don't need to edit the value of the textbox you can make the property readonly as follows.如果您不需要编辑文本框的值,您可以将属性设为只读,如下所示。

Public ReadOnly Property textboxValue as String
     Get
          Return MyTextBox.text
     End Get
End Property

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM