none
Get previous right click position (coordinates) from C# Application? RRS feed

  • Question

  • Hello,

    I have an small application that is fired from context menu in right click.

    Actually, I can get the coordinations/position of the mouse in the point 2 (see the picture below).

    I used this code:

    FirstXPosition = Cursor.Position.X;

    FirstYPosition = Cursor.Position.Y;


    Unforunately, I really needed to position in the point 1 (see the picture above) when the user right clicked. 

    Is it possible to get those coordinates? It is not possible to substract or estimate because the right click some times opens in the top or the bottom.

    Thank you!

    Tuesday, February 25, 2020 9:45 AM

Answers

  • If your application is launched by Explorer Context Menu (added at HKEY_CLASSES_ROOT\*\shell)

    the context menu is already destroyed when the application is launched and API calls like GetMessagePos

    will be too late...

    Tuesday, February 25, 2020 7:44 PM

All replies

  • If you want the Point you can use the open event.

    private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
    {
        Point item = ((ContextMenuStrip) sender).Location;            
    }


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, February 25, 2020 11:59 AM
    Moderator
  • Hello Karen,

    This is not  ContextMenuStrip component. This Context menu is from Window Explorer. So I cannot use the event you mentioned,

    I captured this position right before the constructor/Load.

    FirstXPosition = Cursor.Position.X;

    FirstYPosition = Cursor.Position.Y;


    Thank you!

    Tuesday, February 25, 2020 12:50 PM
  • Hello Karen,

    This is not  ContextMenuStrip component. This Context menu is from Window Explorer. So I cannot use the event you mentioned,

    I captured this position right before the constructor/Load.

    FirstXPosition = Cursor.Position.X;

    FirstYPosition = Cursor.Position.Y;


    Thank you!

    Please in the future supply details like that so I and others don't waste time on a uncomplete question. I could had answered this but not now, no time.

    Here is a starting point

    https://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Tuesday, February 25, 2020 12:54 PM
    Moderator
  • I hope you can reply this when u have time ;)
    Tuesday, February 25, 2020 7:22 PM
  • I hope you can reply this when u have time ;)
    Sorry but last time I replied you didn't care for the message so I'm done replying.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, February 25, 2020 7:29 PM
    Moderator
  • If your application is launched by Explorer Context Menu (added at HKEY_CLASSES_ROOT\*\shell)

    the context menu is already destroyed when the application is launched and API calls like GetMessagePos

    will be too late...

    Tuesday, February 25, 2020 7:44 PM