Vb.net visual basic变量按钮名称
在那 我不能这样工作 我有一些按钮名称,如Vb.net visual basic变量按钮名称,vb.net,Vb.net,在那 我不能这样工作 我有一些按钮名称,如btnOda101,btnOda201,btnOda301 我想使用btnid而不是101102 我怎么做呢?你可以使用这样的字典 Dim btnid As Integer dgkayitlar.Rows(selectedrow).Cells(4).Value = btnid Form2.btnOda(btnid).BackColor = Color.Red 你可以这样做。您需要使用格式为btnOda_101的按钮名称,下划线使代码能够拆分id pub
btnOda101
,btnOda201
,btnOda301
我想使用btnid
而不是101102
我怎么做呢?你可以使用这样的字典
Dim btnid As Integer
dgkayitlar.Rows(selectedrow).Cells(4).Value = btnid
Form2.btnOda(btnid).BackColor = Color.Red
你可以这样做。您需要使用格式为
btnOda_101
的按钮名称,下划线使代码能够拆分id
public btnOda as Dictionary(Of Integer, Button)
public Sub InitButtons()
btnOda = new Dictionary(Of Integer, Button)()
btnOda.add(101, btnOda101)
btnOda.add(102, btnOda102)
btnOda.add(301, btnOda301)
'...
End Sub
public Sub MyFunc()
Dim btnid As Integer
btnOda(btnid).BackColor = Color.Red
End Sub
您可以通过提问提供更多信息。
Dim btnId As Integer = 101
'Get list of buttons
Dim buttons = From c In Controls Where TypeOf (c) Is Button Select c
'Find the button with the desired ID
Dim button = (From b In buttons Where b.name.ToString.Split("_")(1) = btnId Select b).FirstOrDefault
'Use that button
Dim myButton As Button = CType(button, Button)
myButton.BackColor = Color.Red