Capture object's top clicked and apply in another vb.net

0

I'm creating a simple function and I need to identify the name of the object clicked on, and then collect its top .

Private Sub sidebar_bt_all_MouseHover(sender As Object, e As EventArgs) Handles sidebar_bt_all.MouseHover
    sidebar_bar_hover_animation.Top = sidebar_bt_all.Top
End Sub

In the code above, it is taking the top of the object, but it is referencing the object directly.

What I need is that on any clicked button your% .co_de% is captured and applied to top

    
asked by anonymous 02.05.2017 / 22:46

1 answer

0

Answering your Question

You can add the code below in all button click events:

Dim myButton As Button = CType(sender, Button)
sidebar_bar_hover_animation.Top = myButton.Top

Best solution in my opinion

Create a function by passing the sender of each button click event to it, and call this function within each click event.

Private Function GetTop(sender As Object)
    Dim myButton As Button = CType(sender, Button)
    sidebar_bar_hover_animation.Top = myButton.Top
End Function

and call in function:

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    GetTop(sender)
End Sub
    
19.05.2017 / 14:21