我有按顺序命名的单选按钮,例如“Jbtn1”到“Jbtn20”。我尝试使用 for 循环使用 set toolTip 来命名这些按钮。
Dim toolTip1 As New ToolTip()
For j As Integer = 1 To 20
Dim pinInfo As String = "J2-" & j
'Tried to convert the buttonName as Control , but got an error as
'Value of string cannot be converted to systems.windows.forms.control
Dim buttonName As Control = "Jbtn" & j
toolTip1.SetToolTip(buttonName, pinInfo)
Next
如有任何建议,我们将不胜感激。
最佳答案
你可以这样做:
Dim toolTip1 As New ToolTip()
For j As Integer = 1 To 20
Dim pinInfo As String = "J2-" & j
Dim control As Control = Me.Controls.Item("Jbtn" & j)
toolTip1.SetToolTip(control, pinInfo)
Next
此代码使用表单的 Controls
属性来访问表单上的控件。您可以使用控件
上的索引器按名称查找各个控件。
关于vb.net - 如何循环遍历具有按顺序排列的控件名称的systems.windows.forms.controls?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34798520/