Home > Back-end >  vb.net position dialog on mouse location
vb.net position dialog on mouse location

Time:01-13

I have an datagridview.columnheadermouseclick eventhandler this one has e as datagridviewcellmouseeventargs however e.location doesn't give me the mouse location, which I hoped it would.

With that in mind I tried accomplishing this (I have set StartPosition property of FormFilter to Manual)

Private Sub filterclm(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DGV.ColumnHeaderMouseClick
    Using filter As New FormFilter
        filter.Location = e.Location 'wrong location
        If filter.ShowDialog(Me) = DialogResult.OK Then
            ...
        End If
    End Using
End Sub

How should I get the real location of the mouse?

CodePudding user response:

e.location in the ColumnHeaderMouseClick event handler will hold the location relative to the column cell.

If you want to show your new FormFilter form where the mouse cursor is, you can actually ignore it and use the static property Cursor.Position.
It will give you the position relative to the whole screen, which is what you need in order to set the Location of a new form:

filter.Location = Cursor.Position
  • Related