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

  • Home
  • SEARCH
  • 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 3343762
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:59:31+00:00 2026-05-18T00:59:31+00:00

I have a form with child controls. I want when user move mouse over

  • 0

I have a form with child controls.
I want when user move mouse over the form, the form will be closed.
So I catch mouse enter and move leave on the form. But if I move mouse on any controls in form, mouse leave event will be also caught.

Please help me to solve this problem. Thanks.

UPDATE:
When the cursor’s position is on the form’s caption region (this region is called non-client region). I move mouse out of this region, I can’t receive the WM_MOUSELEAVE message as well as WM_NCMOUSELEAVE. Please help me in this problem. I want to receive a message when move mouse out of this region. Thanks.

  • 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-18T00:59:31+00:00Added an answer on May 18, 2026 at 12:59 am

    Essentially you want to check if the cursor is in the scope of the control. Here is the solution:

    (1) Add a Panel in the form which is the same size as your Form, and move all controls in the form to the panel. It’s easy to change: open MyForm.designer.cs, add the panel, and change all statements like this.Controls.Add(myLabel); to this.myPanel.Controls.Add(myLabel);.

    (2) Deal with MouseEnter and MouseLeave events of the panel you added.

    myPanel.MouseEnter += (sender, e) =>
    {
        //enter
    };
    
    myPanel.MouseLeave += (sender, e) =>
    {
       if (Cursor.Position.X < myPanel.Location.X 
           || Cursor.Position.Y < myPanel.Location.Y
           || Cursor.Position.X > myPanel.Location.X + myPanel.Width 
           || Cursor.Position.Y > myPanel.Location.Y + myPanel.Height)
       {
           //out of scope
       }
    };
    

    (3) Why not use Form in step 2? Why do we need a Panel with the same size? Try it yourself. The narrow border of the form will make you crazy.

    (4) You can make the if statements in step 2 to an extension method, which is helpful to furthur usage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to detect when the user moves the mouse over the Form and
I have a thread running on a child form, I want to activate a
I have a user control on a form that can spawn several non-modal child
I have a child form that is throwing an ApplicationException in the Load event
I have a need to close a parent form from within child form from
I have a form with many input fields. When I catch the submit form
I have a form in which people will be entering dollar values. Possible inputs:
I have a form that calls a custom child form. The child form is
I have a base form with two buttons (e.g. OK and Cancel). I want
I have a form with many controls (treeview , memo ,listbox ,panels etc ).

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.