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 6471557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:14:16+00:00 2026-05-25T06:14:16+00:00

If you place a panel in a new C# project and capture it’s MouseMove

  • 0

If you place a panel in a new C# project and capture it’s MouseMove event like this:

private void panel1_MouseMove(object sender, MouseEventArgs e)
{
    if (e.Button != MouseButtons.Left)
        return;

    Console.WriteLine("e.X: {0}, e.Y: {1}", e.X, e.Y);
}

It tells you the client coordinates of the mouse while the left mouse button is held down, even if the cursor goes outside of the panel.

However, if you are holding down left mouse button in the container and then, while holding down left mouse button, click any other mouse button on your mouse, it no longer calls MouseMove while outside the bounds of the container.

Is there any way to change this? Thanks for reading.

  • 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-25T06:14:16+00:00Added an answer on May 25, 2026 at 6:14 am

    1: If you are trying to get it to work only when the left button is down, try the following:

    bool mouseDown = false;
    
    private void panel1_MouseMove(object sender, MouseEventArgs e)
    {
        if (!mouseDown)
            return;
    
        Console.WriteLine("e.X: {0}, e.Y: {1}", e.X, e.Y);
    }
    
    private void panel1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
            mouseDown = true;
    }
    
    private void panel1_MouseUp(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
            mouseDown = false;
    }
    

    2: Otherwise, if you want it to work when any mouse button is down, try the following:

    int mouseDown = 0;
    
    private void panel1_MouseMove(object sender, MouseEventArgs e)
    {
        if (mouseDown == 0)
            return;
    
        Console.WriteLine("e.X: {0}, e.Y: {1}", e.X, e.Y);
    }
    
    private void panel1_MouseDown(object sender, MouseEventArgs e)
    {
        mouseDown++;
    }
    
    private void panel1_MouseUp(object sender, MouseEventArgs e)
    {
        mouseDown--;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i careate button control and place in panel but not working? protected void Button1_Click(object
I'm going to try this new cloud technology. So I think the best place
Hi I'm new to WPF and I want to place a Panel upon a
I'm trying to place 4 of my image containers into a new pane, having
I'm trying to place this menu on the left hand side of the page:
In my project i added a usercontrol to a panel.when i try to add
I have write this code for displaying some set of colors from panel: import
I am new to Java Swing application development. I am looking to place a
I have a panel where I place several mini-panels, side-by-side, with different sizes and
... I ask this mainly because when I try to use the update panel,

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.