--- title: "How to: Resize a Canvas by Using a Thumb" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "resizing Canvas control [WPF]" - "controls [WPF], Thumb" - "controls [WPF], Canvas" - "Thumb control [WPF]" - "Canvas control [WPF]" ms.assetid: 7dc9f435-726c-4d4d-be41-eb24cfe17bef --- # How to: Resize a Canvas by Using a Thumb This example shows how to use a control to resize a control. ## Example The control provides drag functionality that can be used to move or resize controls by monitoring the , and events of the . The user begins a drag operation by pressing the left mouse button when the mouse pointer is paused on the control. The drag operation continues as long as the left mouse button remains pressed. During the drag operation, the can occur more than once. Each time it occurs, the class provides the change in position that corresponds to the change in mouse position. When the user releases the left mouse button, the drag operation is finished. The drag operation only provides new coordinates; it does not automatically reposition the . The following example shows a control that is the child element of a control. The event handler for its event provides the logic to move the and resize the . The event handlers for the and event change the color of the during a drag operation. The following example defines the . [!code-xaml[Thumb#thumb](~/samples/snippets/csharp/VS_Snippets_Wpf/Thumb/CSharp/Pane1.xaml#thumb)] The following example shows the event handler that moves the and resizes the in response to a mouse movement. [!code-csharp[Thumb#2](~/samples/snippets/csharp/VS_Snippets_Wpf/Thumb/CSharp/Pane1.xaml.cs#2)] The following example shows the event handler. [!code-csharp[Thumb#DragStartedHandler](~/samples/snippets/csharp/VS_Snippets_Wpf/Thumb/CSharp/Pane1.xaml.cs#dragstartedhandler)] [!code-vb[Thumb#DragStartedHandler](~/samples/snippets/visualbasic/VS_Snippets_Wpf/Thumb/VisualBasic/Pane1.xaml.vb#dragstartedhandler)] The following example shows the event handler. [!code-csharp[Thumb#DragCompletedHandler](~/samples/snippets/csharp/VS_Snippets_Wpf/Thumb/CSharp/Pane1.xaml.cs#dragcompletedhandler)] [!code-vb[Thumb#DragCompletedHandler](~/samples/snippets/visualbasic/VS_Snippets_Wpf/Thumb/VisualBasic/Pane1.xaml.vb#dragcompletedhandler)] For the complete sample, see [Thumb Drag Functionality Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Drag%20and%20Drop/DragDropThumbOps). ## See also - - - -