Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/how-to-resize-a-canvas-by-using-a-thumb.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

4.0 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Resize a Canvas by Using a Thumb 03/30/2017
csharp
vb
resizing Canvas control [WPF]
controls [WPF], Thumb
controls [WPF], Canvas
Thumb control [WPF]
Canvas control [WPF]
7dc9f435-726c-4d4d-be41-eb24cfe17bef

How to: Resize a Canvas by Using a Thumb

This example shows how to use a xref:System.Windows.Controls.Primitives.Thumb control to resize a xref:System.Windows.Controls.Canvas control.

Example

The xref:System.Windows.Controls.Primitives.Thumb control provides drag functionality that can be used to move or resize controls by monitoring the xref:System.Windows.Controls.Primitives.Thumb.DragStarted, xref:System.Windows.Controls.Primitives.Thumb.DragDelta and xref:System.Windows.Controls.Primitives.Thumb.DragCompleted events of the xref:System.Windows.Controls.Primitives.Thumb.

The user begins a drag operation by pressing the left mouse button when the mouse pointer is paused on the xref:System.Windows.Controls.Primitives.Thumb control. The drag operation continues as long as the left mouse button remains pressed. During the drag operation, the xref:System.Windows.Controls.Primitives.Thumb.DragDelta can occur more than once. Each time it occurs, the xref:System.Windows.Controls.Primitives.DragDeltaEventArgs 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 xref:System.Windows.Controls.Primitives.Thumb.

The following example shows a xref:System.Windows.Controls.Primitives.Thumb control that is the child element of a xref:System.Windows.Controls.Canvas control. The event handler for its xref:System.Windows.Controls.Primitives.Thumb.DragDelta event provides the logic to move the xref:System.Windows.Controls.Primitives.Thumb and resize the xref:System.Windows.Controls.Canvas. The event handlers for the xref:System.Windows.Controls.Primitives.Thumb.DragStarted and xref:System.Windows.Controls.Primitives.Thumb.DragCompleted event change the color of the xref:System.Windows.Controls.Primitives.Thumb during a drag operation. The following example defines the xref:System.Windows.Controls.Primitives.Thumb.

[!code-xamlThumb#thumb]

The following example shows the xref:System.Windows.Controls.Primitives.Thumb.DragDelta event handler that moves the xref:System.Windows.Controls.Primitives.Thumb and resizes the xref:System.Windows.Controls.Canvas in response to a mouse movement.

[!code-csharpThumb#2]

The following example shows the xref:System.Windows.Controls.Primitives.Thumb.DragStarted event handler.

[!code-csharpThumb#DragStartedHandler] [!code-vbThumb#DragStartedHandler]

The following example shows the xref:System.Windows.Controls.Primitives.Thumb.DragCompleted event handler.

[!code-csharpThumb#DragCompletedHandler] [!code-vbThumb#DragCompletedHandler]

For the complete sample, see Thumb Drag Functionality Sample.

See also