MOUSE HOVER MULTIPLE BUTTONS

ben reitman

Total Post:96

Points:676
Posted by  ben reitman
VB.Net 
 1132  View(s)
Ratings:
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. 

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Mouse Hover Multiple Buttons

    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


Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!