Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4334100
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:28:57+00:00 2026-05-21T10:28:57+00:00

What is the easiest way to determine if my current cursor position is over

  • 0

What is the easiest way to determine if my current cursor position is over a particular (WinForm) control?

I can – of course – calculate the control’s position and then check whether the cursor position is within this rectangel. But maybe there is something already existing for this….

I cannot use OnMouseOver event for this, because the decisions must take place within (another) event. In order to further explain here is what I do (in pseudo code). The problem is, when I start the drag event, then move to another control (outside this), release the mouse to finish the drop, the context menu is displayed on the “wrong” control (the drop target). This is what I want to avoid….

 private void TableControlMouseDown(object sender, MouseEventArgs e)
    {
        ...
        // this is a User control with some sub controls 

        // when selected start drag and drop
        if (SOMEConditions)
        {
            // start drag and drop operation
            DragAndDropWrapper dragAndDropWrapper = new DragAndDropWrapper(this.ObjectsToDrag, this);
            this._subControl.DoDragDrop(dragAndDropWrapper, DragDropEffects.Copy);
        }

        // context menu

        // check should go here
        // something like "is pt still over "this" or over the drag target ...
        Point pt = this._subControl.PointToClient(Control.MousePosition);
        this._myContextMenu.Show(this._subControl, pt);
    }

— as of today —
See below for the extension method I am using at the moment …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:28:58+00:00Added an answer on May 21, 2026 at 10:28 am

    This is the best solution I have found so far. Actually it is pretty easy (as always once you know how to do it 😉 since PointToClient gives me relative coordinates which drastically reduces the effort …. As an extension method it also is easy to use with all controls.

        /// <summary>
        ///   Is the mouse pointer over the control?
        /// </summary>
        /// <param name = "control"></param>
        /// <returns></returns>
        public static bool IsMouseOverControl(this Control control)
        {
            if (control == null) throw new ArgumentNullException("control");
            Contract.EndContractBlock();
    
            Point pt = control.PointToClient(Control.MousePosition);
            return (pt.X >= 0 && pt.Y >= 0 && pt.X <= control.Width && pt.Y <= control.Height);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the easiest way to determine if a reflected property can be assigned
What's the easiest way to determine an elements position relative to the document/body/browser window?
What is the easiest way to compare strings in Python, ignoring case? Of course
Whats the easiest way to determine which Java class is compiled with the wrong
What's the easiest way to determine if the last day of the year falls
I have a string 8,7,13,14,16 Whats the easiest way to determine if a given
Normally the easiest way to debug is using printf . What can I do
What is the easiest way to determine the maximum match length of a regular
What is the easiest way to determine if ALL items in a multiple HTML
What's the easiest way to determine which version of Flask is installed?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.