Home > DeveloperSection > Forums > Mouse Hover Multiple Buttons
ben reitman
ben reitman

Total Post:96

Points:676
Posted on    June-11-2013 7:49 AM

 VB.Net VB.Net 
Ratings:


 1 Reply(s)
 912  View(s)
Rate this:
Hi Developers, 

I want to get value the label.text when my mouse hovers on the button and passing to it to the textbox. I have 5 buttons and 5 labels in my application. 

The code

    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

The problem is I would like this all private sub to 1 private sub but I have no idea.. I try this code :

     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

Thanks in advance. 



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    June-12-2013 7:43 AM

Hi Ben,

You can try as following 

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



Don't want to miss updates? Please click the below button!

Follow MindStick