Capture Top of clicked object and apply on another Vb.net

Asked

Viewed 69 times

0

Opa, I am creating a simple function and in it I need to identify the name of the clicked object, and from there collect your 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’s taking the top of the object, but it’s referencing the object directly.

What I need is for any button clicked to be captured your .top and applied in sidebar_bar_hover_animation

1 answer

0

Answering to 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

A function is created by passing the Sender of each button click event to it, and calling 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.