WPF——Thumb

Thumb类,表示可由用户拖动的控件。其主要三个事件分别DragDelta,DragStarted,DragCompleted.

 

DragDelta——当 Thumb 控件具有逻辑焦点和鼠标捕获时,随着鼠标位置更改发生一次或多次。

DragStarted——在 Thumb 控件接收逻辑焦点和鼠标捕获时发生。

DragCompleted——在 Thumb 控件失去鼠标捕获时发生。

 1  <Window.Resources>
2 <ResourceDictionary>
3 <ControlTemplate x:Key="template1">
4 <Ellipse Width="60" Height="30">
5 <Ellipse.Fill>
6 <SolidColorBrush Color="Black">SolidColorBrush>
7 Ellipse.Fill>
8 Ellipse>
9 ControlTemplate>
10 ResourceDictionary>
11 Window.Resources>
12
13 <Canvas Name="myCanvas">
14 <Thumb Name="myThumb" DragDelta="onDragDelta" Background="Blue" DragStarted="myThumb_DragStarted" DragCompleted="myThumb_DragCompleted"
15 Canvas.Left="0" Canvas.Top="0" Width="200" Height="200"/>
16
17
18 Canvas>

 

 1    void onDragDelta(object sender, DragDeltaEventArgs e)
2 {
3 Canvas.SetLeft(myThumb, Canvas.GetLeft(myThumb) + e.HorizontalChange);
4
5 Canvas.SetTop(myThumb, Canvas.GetTop(myThumb) + e.VerticalChange);
6
7 }
8
9 private void myThumb_DragStarted(object sender, DragStartedEventArgs e)
10 {
11 myThumb.Background = Brushes.Orange;
12 }
13
14 private void myThumb_DragCompleted(object sender, DragCompletedEventArgs e)
15 {
16 myThumb.Background = Brushes.Blue;
17 }




转载于:https://www.cnblogs.com/January/archive/2012/04/06/2434205.html

你可能感兴趣的:(WPF——Thumb)