Thumb.DragDelta 事件

定义

Thumb 控件具有逻辑焦点和鼠标捕获时,随着鼠标位置更改发生一次或多次。Occurs one or more times as the mouse changes position when a Thumb control has logical focus and mouse capture.

public:
 event System::Windows::Controls::Primitives::DragDeltaEventHandler ^ DragDelta;
public event System.Windows.Controls.Primitives.DragDeltaEventHandler DragDelta;
member this.DragDelta : System.Windows.Controls.Primitives.DragDeltaEventHandler 
Public Custom Event DragDelta As DragDeltaEventHandler 

示例

下面的示例演示如何将DragDelta事件的事件处理程序分配Thumb给控件, 以及如何定义事件处理程序。The following example shows how to assign an event handler for the DragDelta event to a Thumb control, and how to define the event handler. 有关完整示例, 请参阅Thumb 拖动功能示例For the complete sample, see Thumb Drag Functionality Sample.

<Thumb Name="myThumb" Canvas.Left="80" Canvas.Top="80" Background="Blue" 
      Width="20" Height="20" DragDelta="onDragDelta" 
      DragStarted="onDragStarted" DragCompleted="onDragCompleted"
      />
void onDragDelta(object sender, DragDeltaEventArgs e)
{
    //Move the Thumb to the mouse position during the drag operation
    double yadjust = myCanvasStretch.Height + e.VerticalChange;
    double xadjust = myCanvasStretch.Width + e.HorizontalChange;
    if ((xadjust >= 0) && (yadjust >= 0))
    {
        myCanvasStretch.Width = xadjust;
        myCanvasStretch.Height = yadjust;
        Canvas.SetLeft(myThumb, Canvas.GetLeft(myThumb) +
                                e.HorizontalChange);
        Canvas.SetTop(myThumb, Canvas.GetTop(myThumb) +
                                e.VerticalChange);
        changes.Text = "Size: " +
                        myCanvasStretch.Width.ToString() +
                         ", " +
                        myCanvasStretch.Height.ToString();
    }
}

注解

当用户在将鼠标指针Thumb悬停在控件上时按下鼠标左键时,控件接收焦点和鼠标捕获。ThumbThe Thumb control receives focus and mouse capture when the user presses the left mouse button while pausing the mouse pointer over the Thumb control. Thumb用户释放鼠标左键或CancelDrag调用方法时, 控件将失去鼠标捕获。The Thumb control loses mouse capture when the user releases the left mouse button, or when the CancelDrag method is called.

每次DragDelta鼠标位置在屏幕上移动时, 都会发生一个新事件。A new DragDelta event occurs each time the mouse position moves on the screen. 因此, 当Thumb控件具有鼠标捕获时, 可以多次引发此事件而不会有限制。Therefore, this event can be raised multiple times without a limit when a Thumb control has mouse capture.

路由事件信息Routed Event Information

标识符字段Identifier field DragDeltaEvent
路由策略Routing strategy 冒泡Bubbling
委托Delegate DragDeltaEventHandler

适用于

另请参阅