#691 – IsMouseCaptured Indicates Whether Mouse Is Currently Captured

You can use the CaptureMouse and ReleaseMouseCapture methods to capture/release the mouse pointer, so that a user interface element will get all future mouse events.

You can also check the IsMouseCaptured property of a UIElement object at any time, to see whether this element has currently captured the mouse.  In the example below, IsMouseCaptured is true while we’re moving the mouse pointer across the label only while we have a mouse button pressed.

        private void Feast_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Console.WriteLine("Feast_MouseDown");
            Label l = e.Source as Label;
            l.CaptureMouse();
        }

        private void Feast_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Console.WriteLine("Feast_MouseUp");
            Label l = e.Source as Label;
            l.ReleaseMouseCapture();
        }

        private void Feast_MouseMove(object sender, MouseEventArgs e)
        {
            Label l = e.Source as Label;
            Console.WriteLine(string.Format("IsMouseCaptured={0}", l.IsMouseCaptured));
        }

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

One Response to #691 – IsMouseCaptured Indicates Whether Mouse Is Currently Captured

  1. Pingback: Dew Drop – November 15, 2012 (#1,443) | Alvin Ashcraft's Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: