Files
docs-desktop/dotnet-desktop-guide/framework/wpf/advanced/how-to-make-an-object-follow-the-mouse-pointer.md
T
Andy (Steve) De George be103da07e Replace various WPF include files with content (#1335)
* net-current-v30plus-md.md

* net-current-v40plus-md.md

* tla2sharptla-ui-md.md

* tla2sharptla-uiautomation-md.md

* tla2sharptla-winclient-md.md

* tla2sharptla-xaml-md.md

* tlasharptla-ui-md.md

* tlasharptla-uiautomation-md.md

* tlasharptla-winclient-md.md

* tlasharptla-xaml-md.md

* fix warnings
2022-03-16 12:14:11 -04:00

1.6 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Make an Object Follow the Mouse Pointer 03/30/2017
csharp
vb
following the mouse pointer (cursor)
mouse pointer (cursor), making objects follow
cursor (mouse pointer), making objects follow
50b20415-14bc-405c-baf3-2fb254fffde3

How to: Make an Object Follow the Mouse Pointer

This example shows how to change the dimensions of an object when the mouse pointer moves on the screen.

The example includes an user interface (UI) and a code-behind file that creates the event handler.

Example

The following XAML creates the UI, which consists of an xref:System.Windows.Shapes.Ellipse inside of a xref:System.Windows.Controls.StackPanel, and attaches the event handler for the xref:System.Windows.UIElement.MouseMove event.

[!code-xamlmouseMoveWithPointer#MouseMoveWithPointerXAML]

The following code behind creates the xref:System.Windows.UIElement.MouseMove event handler. When the mouse pointer moves, the height and the width of the xref:System.Windows.Shapes.Ellipse are increased and decreased.

[!code-csharpmouseMoveWithPointer#MouseMovePointerGetPosition] [!code-vbmouseMoveWithPointer#MouseMovePointerGetPosition]

See also