Thumb.DragDelta 事件
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當 Thumb 控制項具有邏輯焦點和滑鼠捕捉時,會在滑鼠變更位置時出現一次或多次。
public:
event System::Windows::Controls::Primitives::DragDeltaEventHandler ^ DragDelta;
C#
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 功能範例。
XAML
<Thumb Name="myThumb" Canvas.Left="80" Canvas.Top="80" Background="Blue"
Width="20" Height="20" DragDelta="onDragDelta"
DragStarted="onDragStarted" DragCompleted="onDragCompleted"
/>
C#
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 |
產品 | 版本 |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |