How do you get the control that was clicked to open a ContextMenuStrip?

前端 未结 5 521
醉梦人生
醉梦人生 2020-12-16 18:47

I\'m using a ContextMenuStrip for multiple controls and I\'m trying to figure out the best way to get the control that was actually clicked on to open the Conte

5条回答
  •  太阳男子
    2020-12-16 19:32

    Private Sub cmsRightClick_Click(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cmsRightClick.MouseClick
        Dim s As String = CType(sender, ContextMenuStrip).GetItemAt(CType(sender, ContextMenuStrip).DisplayRectangle.X, _
         CType(sender, ContextMenuStrip).DisplayRectangle.Y + e.Y).Text.Trim()
    
    
        MsgBox(s)
        Select Case s 
            Case Is = "Select Summary Total"
                Dim x = 0
            Case Is = "Select Collections"
                Dim x = 1
            Case Is = "UnSelect"
                Dim x = 2
            Case Is = "Reconcile"
                Dim x = 3
            Case Is = "Undo Reconciliation"
                Dim x = 4
        End Select
    End Sub
    

提交回复
热议问题