Thumb.DragDelta 事件

定義

Thumb 控制項具有邏輯焦點和滑鼠捕捉時,會在滑鼠變更位置時出現一次或多次。

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 控制項,以及如何定義事件處理常式。 如需完整的範例,請參閱 Thumb Drag 功能範例

<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 暫停滑鼠指標時按下滑鼠左鍵時,控制項 Thumb 會收到焦點和滑鼠擷取。 當使用者 Thumb 放開滑鼠左鍵或呼叫 方法時 CancelDrag ,控制項會遺失滑鼠擷取。

每次滑鼠位置在畫面上移動時,就會發生新的 DragDelta 事件。 因此,當控制項有滑鼠擷取時,可以多次引發此事件,而不會 Thumb 有限制。

路由事件資訊

識別碼欄位 DragDeltaEvent
路由策略 鼓 泡
代理人 DragDeltaEventHandler

適用於

另請參閱