--- title: "How to: Make an Object Follow the Mouse Pointer" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "following the mouse pointer (cursor)" - "mouse pointer (cursor), making objects follow" - "cursor (mouse pointer), making objects follow" ms.assetid: 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 [!INCLUDE[TLA#tla_xaml](../../../includes/tlasharptla-xaml-md.md)] file that creates the [!INCLUDE[TLA#tla_ui](../../../includes/tlasharptla-ui-md.md)] and a code-behind file that creates the event handler. ## Example The following XAML creates the [!INCLUDE[TLA2#tla_ui](../../../includes/tla2sharptla-ui-md.md)], which consists of an inside of a , and attaches the event handler for the event. [!code-xaml[mouseMoveWithPointer#MouseMoveWithPointerXAML](~/samples/snippets/csharp/VS_Snippets_Wpf/mouseMoveWithPointer/CSharp/Window1.xaml#mousemovewithpointerxaml)] The following code behind creates the event handler. When the mouse pointer moves, the height and the width of the are increased and decreased. [!code-csharp[mouseMoveWithPointer#MouseMovePointerGetPosition](~/samples/snippets/csharp/VS_Snippets_Wpf/mouseMoveWithPointer/CSharp/Window1.xaml.cs#mousemovepointergetposition)] [!code-vb[mouseMoveWithPointer#MouseMovePointerGetPosition](~/samples/snippets/visualbasic/VS_Snippets_Wpf/mouseMoveWithPointer/VisualBasic/Window1.xaml.vb#mousemovepointergetposition)] ## See also - [Input Overview](input-overview.md)