我有5个按钮和5个标签。当我的鼠标悬停在按钮上并传递给文本框时,我想获得label.text值。
代码
Private Sub btnRoomA_MouseHover(sender As Object, e As EventArgs) Handles btnRoomA.MouseHover
notransaksiMouse = lblTransaksiRA.Text
textbox1.text = noTransaksiMouse
End Sub
Private Sub btnRoomB_MouseHover(sender As Object, e As EventArgs) Handles btnRoomB.MouseHover
notransaksiMouse = lblTransaksiRB.Text
textbox1.text = noTransaksiMouse
End Sub
Private Sub btnRoomC_MouseHover(sender As Object, e As EventArgs) Handles btnRoomC.MouseHover
notransaksiMouse = lblTransaksiRC.Text
textbox1.text = noTransaksiMouse
End Sub
Private Sub btnRoomD_MouseHover(sender As Object, e As EventArgs) Handles btnRoomD.MouseHover
notransaksiMouse = lblTransaksiRD.Text
textbox1.text = noTransaksiMouse
End Sub
Private Sub btnRoomE_MouseHover(sender As Object, e As EventArgs) Handles btnRoomE.MouseHover
notransaksiMouse = lblTransaksiRE.Text
textbox1.text = noTransaksiMouse
End Sub
问题是我希望这个私有子对1私有子,但我不知道.. 我试试这段代码:
Private Sub btnRoomE_MouseHover(sender As Object, e As EventArgs) Handles btnRoomA.MouseHover,btnRoomB.MouseHover,btnRoomC.MouseHover,btnRoomD.MouseHover,btnRoomE.MouseHover
notransaksiMouse = lblTransaksiRE.Text
textbox1.text = noTransaksiMouse
End Sub
答案 0 :(得分:1)
试试这个......
Private Sub btnRoomMouseHover(sender As Object, e As EventArgs) Handles btnRoomA.MouseHover, btnRoomB.MouseHover, btnRoomC.MouseHover, btnRoomD.MouseHover, btnRoomE.MouseHover
Dim s as String = CType(sender,Button).Name
Dim lbl as Label = CType(Me.Controls("lblTransaksiR" & s.Substring(7)), Label)
notransaksiMouse = lbl.Text
textbox1.text = noTransaksiMouse
End Sub
答案 1 :(得分:0)
试试这个:
Private Sub btn_MouseHover(sender As Object, e As EventArgs) & _
Handles btnRoomA.MouseHover, btnRoomB.MouseHover, btnRoomC.MouseHover, btnRoomD.MouseHover, btnRoomE.MouseHover
Dim btn As Button = CType(sender, Button)
Select Case btn.Name
Case "btnRoomA" : noTransaksiMouse = lblTransaksiRA.Text
Case "btnRoomB" : noTransaksiMouse = lblTransaksiRB.Text
Case "btnRoomC" : noTransaksiMouse = lblTransaksiRC.Text
Case "btnRoomD" : noTransaksiMouse = lblTransaksiRD.Text
Case "btnRoomE" : noTransaksiMouse = lblTransaksiRE.Text
End Select
TextBox1.Text = noTransaksiMouse
End Sub