title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | description | |||||
---|---|---|---|---|---|---|---|---|---|---|
How to: Make an Object Follow the Mouse Pointer |
03/30/2017 |
|
|
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. |
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.
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]