1

我有 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
4

2 回答 2

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
于 2013-06-10T15:17:49.057 回答
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
于 2013-06-10T15:21:21.300 回答