例如,我想根據我在框中寫的內容宣告文本框。如果我寫 textbox1. 如果我輸入 textbox2.text 那么它將是 textbox2.text
Dim txt As TextBox = TextBox2.Text.ToString
Dim txt As String = TextBox2.Text
沒有一個方法是有效的
uj5u.com熱心網友回復:
您的措辭雖然令人困惑,但似乎您想要將 TextBox 的 NAME 鍵入到 TextBox 中,然后能夠檢索命名的 TextBox 的內容。如果這是正確的,您可能正在尋找帶有 recurse 選項的Controls.Find():
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim txtBoxName As String = TextBox1.Text.Trim
If txtBoxName.Length > 0 Then
Dim ctl As Control = Me.Controls.Find(txtBoxName, True).FirstOrDefault
If Not IsNothing(ctl) AndAlso TypeOf (ctl) Is TextBox Then
Dim tb As TextBox = DirectCast(ctl, TextBox)
' ... do something with "tb" ...
Dim value As String = tb.Text
MessageBox.Show(value)
Else
MessageBox.Show("Control not found, or incorrect type!")
End If
End If
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/361774.html
標籤:网络
