Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 1.86 KB

how-to-make-an-object-follow-the-mouse-pointer.md

File metadata and controls

33 lines (24 loc) · 1.86 KB
title ms.date dev_langs helpviewer_keywords ms.assetid description
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
Learn how to make an object follow the mouse pointer and change the dimensions of an object when the mouse pointer moves on the screen.

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 Extensible Application Markup Language (XAML) file that creates the 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