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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:48:29+00:00 2026-05-21T13:48:29+00:00

I have a strange question and a vb.net 2010 and wpf4 project. I have

  • 0

I have a strange question and a vb.net 2010 and wpf4 project. I have a label that, when clicked, captures the mouse (MyLabel.captureMouse) and follows it around the screen until the mouse clicks again, at which point the object and the mousecapture is released.

However, I still need the functionality of mouseenter for another object. How do I get these two things to work together?

EDIT: There are two solutions to this, it seems, one of which I discovered. However, since Rick’s should work as well (though untested because of my deadline), and I hate answering my own questions on here, I accepted his answer.

In the interim of waiting for him to comment back to a problem I had, I wound up discovering my own solution. Thus, be sure to read both my answer and Rick’s.

  • 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-21T13:48:29+00:00Added an answer on May 21, 2026 at 1:48 pm

    If the other object is one of your objects, then your label and the other object can cooperate while you have the mouse captured using synthetic events. For example, in your mouse move handler, you can check Mouse.DirectlyOver to see if it is the other object and if so, do a little bookkeeping and then call RaiseEvent with either MouseEnter or MouseLeave on the other object. If you have a bunch of these objects then you just have more bookkeeping to do.

    Edit:

    The above refers to Mouse.DirectlyOver which specifically does not work when the mouse is captured. To make the above more concrete and to fix that error, here is a complete working example.

    Here is the markup showing a canvas, a rectangle with mouse capture handling, and an ellipse with enter/leave handling:

    <Grid>
        <Canvas>
            <Rectangle Canvas.Left="0" Canvas.Top="0"
                       Fill="Red" Width="100" Height="100"
                       MouseLeftButtonDown="Rectangle_MouseLeftButtonDown"
                       MouseMove="Rectangle_MouseMove"
                       MouseLeftButtonUp="Rectangle_MouseLeftButtonUp"/>
            <Ellipse Canvas.Left="0" Canvas.Top="100"
                       Fill="Green" Width="100" Height="100"
                       MouseEnter="Ellipse_MouseEnter"
                       MouseLeave="Ellipse_MouseLeave">
                <Ellipse.RenderTransform>
                    <ScaleTransform/>
                </Ellipse.RenderTransform>
            </Ellipse>
        </Canvas>
    </Grid>
    

    and here are the event handlers that demonstrate how to generate synthetic enter/leave events (but only for the ellipse) while the mouse is captured:

        private void Rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var capturer = sender as FrameworkElement;
            capturer.CaptureMouse();
        }
    
        bool over = false;
        UIElement element;
    
        private void Rectangle_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton != MouseButtonState.Pressed) return;
            var capturer = sender as FrameworkElement;
            var hit = VisualTreeHelper.HitTest(this, e.GetPosition(this));
            if (hit == null) return;
            var thisElement = hit.VisualHit as Ellipse;
            var nowOver = thisElement != null;
            if (nowOver) element = thisElement;
            var args = new MouseEventArgs(Mouse.PrimaryDevice, 0);
            if (!over && nowOver) { args.RoutedEvent = UIElement.MouseEnterEvent; element.RaiseEvent(args); }
            if (over && !nowOver) { args.RoutedEvent = UIElement.MouseLeaveEvent; element.RaiseEvent(args); }
            over = nowOver;
        }
    
        private void Rectangle_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            var capturer = sender as FrameworkElement;
            capturer.ReleaseMouseCapture();
        }
    
        private void Ellipse_MouseEnter(object sender, MouseEventArgs e)
        {
            Debug.WriteLine("MouseEnter");
        }
    
        private void Ellipse_MouseLeave(object sender, MouseEventArgs e)
        {
            Debug.WriteLine("MouseLeave");
        }
    

    If you run the demo under the debugger you’lll see that the enter/leave handlers are called whether the mouse is captured or not.

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

Sidebar

Related Questions

I have a procedure in asp.net web site that gives strange result sometimes, I’m
Strange question, I know. Allow me to explain. I have a JavaScript/jQuery function that
I have a project that interacts with a database through ADO.net Data Services. The
I have a strange question! I have developed a website in asp.net webforms, I've
I have probem / strange question, i got algorithm with few for loops and
I have a strange question concerning subroutines: As I'm creating a minimal language and
I have a bit of a strange question. Can anyone tell me where to
I know it is a strange question did someone have had a case where
Right, bit of a strange question; I have been doing some linq to XML
I have a strange requirement to ship an application without bundling .Net framework (to

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.