本文整理汇总了C#中System.Windows.UIElement.CaptureMouse方法的典型用法代码示例。如果您正苦于以下问题:C# UIElement.CaptureMouse方法的具体用法?C# UIElement.CaptureMouse怎么用?C# UIElement.CaptureMouse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.UIElement
的用法示例。
在下文中一共展示了UIElement.CaptureMouse方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public static void Start(UIElement element)
{
if (Element != null)
throw new Exception("Another element is being dragged. Only one element at a time may be dragged.");
Element = element;
Element.CaptureMouse();
Element.MouseMove += new MouseEventHandler(UIElement_MouseMove);
TransformGroup tg = Element.RenderTransform as TransformGroup;
if (tg == null)
{
tg = CreateTransformGroup();
Element.RenderTransform = tg;
}//end if
TranslateTransform tt = tg.Children.Where(t => t is TranslateTransform).SingleOrDefault() as TranslateTransform;
if (tt == null)
tt = new TranslateTransform();
tt.X = 0;
tt.Y = 0;
OnDragStarted(Element);
}
示例2: AddDragHandler
public void AddDragHandler(UIElement canvas)
{
MouseButtonEventHandler startDragging = null;
startDragging = (object sender, MouseButtonEventArgs downEvent) =>
{
if (downEvent.ChangedButton != MouseButton.Middle)
{
downEvent.Handled = false;
return;
}
downEvent.Handled = true;
canvas.CaptureMouse();
var dragStartPos = PointConversions.CanvasFromMouse(downEvent.MouseDevice, canvas);
var originStartPos = _origin.Point;
MouseEventHandler MiddleDragListener = (object o, MouseEventArgs moveEvent) =>
{
var mouse_pos = PointConversions.CanvasFromMouse(moveEvent.MouseDevice, canvas);
_origin.Point = new CanvasPosition
{
X = originStartPos.X + (mouse_pos.X - dragStartPos.X),
Y = originStartPos.Y + (mouse_pos.Y - dragStartPos.Y),
};
};
MouseButtonEventHandler mouseUpListener = null;
mouseUpListener = (object bob, MouseButtonEventArgs upEvent) =>
{
if (upEvent.ChangedButton != MouseButton.Middle)
{
upEvent.Handled = false;
return;
}
canvas.ReleaseMouseCapture();
upEvent.Handled = true;
canvas.MouseMove -= MiddleDragListener;
canvas.MouseUp -= mouseUpListener;
canvas.MouseDown += startDragging;
};
canvas.MouseMove += MiddleDragListener;
canvas.MouseUp += mouseUpListener;
canvas.MouseDown -= startDragging;
};
canvas.MouseDown += startDragging;
}
示例3: sp_PreviewMouseMove
private void sp_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (_isDown)
{
if ((_isDragging == false) && ((Math.Abs(e.GetPosition(this.sp).X - _startPoint.X) > SystemParameters.MinimumHorizontalDragDistance) ||
(Math.Abs(e.GetPosition(this.sp).Y - _startPoint.Y) > SystemParameters.MinimumVerticalDragDistance)))
{
_isDragging = true;
_realDragSource = e.Source as UIElement;
_realDragSource.CaptureMouse();
DragDrop.DoDragDrop(_dummyDragSource, new DataObject("UIElement", e.Source, true), DragDropEffects.Move);
}
}
}
示例4: DoDragDrop
public void DoDragDrop(IDataObject dataObject, UIElement dragSource, bool showDragVisual, bool useVisualBrush, DragDropEffects effects)
{
if (!IsDragging)
{
_useDefaultCursor = true;
_dragScope = Application.Current.MainWindow.Content as FrameworkElement;
bool previousDrop = _dragScope.AllowDrop;
_dragScope.AllowDrop = true;
_dragScope.PreviewDragOver += DragScope_PreviewDragOver;
_dragScope.DragOver += DragScope_DragOver;
_dragScope.DragLeave += DragScope_DragLeave;
_dragScope.DragEnter += DragScope_DragEnter;
_dragScope.GiveFeedback += DragSource_GiveFeedback;
_dragScope.QueryContinueDrag += DragScope_QueryContinueDrag;
var _layer = AdornerLayer.GetAdornerLayer(_dragScope);
if (showDragVisual)
{
_dragAdorner = new DragAdorner(_dragScope, dragSource, useVisualBrush);
_layer.Add(_dragAdorner);
}
IsDragging = true;
_dragHasLeftScope = false;
dragSource.CaptureMouse();
DragDropEffects de = System.Windows.DragDrop.DoDragDrop(dragSource, dataObject, effects);
dragSource.ReleaseMouseCapture();
if (_dragAdorner != null)
{
_layer.Remove(_dragAdorner);
_dragAdorner = null;
}
_dragScope.AllowDrop = previousDrop;
_dragScope.GiveFeedback -= DragSource_GiveFeedback;
_dragScope.DragLeave -= DragScope_DragLeave;
_dragScope.DragLeave -= DragScope_DragEnter;
_dragScope.QueryContinueDrag -= DragScope_QueryContinueDrag;
_dragScope.DragOver -= DragScope_DragOver;
_dragScope.PreviewDragOver -= DragScope_PreviewDragOver;
IsDragging = false;
}
}
示例5: MouseDown
public static void MouseDown(MouseButtonEventArgs e, UIElement element, IControlMouseInteraction control)
{
var location = e.GetPosition(element);
var keysHeld = GetKeysHeld();
float x = (float)location.X;
float y = (float)location.Y;
element.CaptureMouse();
switch (e.ChangedButton)
{
case MouseButton.Left:
control.MouseDown(x, y, MouseButtonType.Left, keysHeld);
break;
case MouseButton.Middle:
control.MouseDown(x, y, MouseButtonType.Middle, keysHeld);
break;
case MouseButton.Right:
control.MouseDown(x, y, MouseButtonType.Right, keysHeld);
break;
}
}
示例6: Select_PreviewMouseLeftButtonDown
/// <summary>
/// Handler for element selection on the canvas providing resizing adorner.
/// </summary>
private void Select_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
#region Remove elsewhere before adding the layer.
if (_selectedElement != null)
{
//Remove the adorner from the selected element
_adornerLayer.Remove(_adornerLayer.GetAdorners(_selectedElement)[0]);
_selectedElement = null;
}
#endregion
_selectedElement = e.Source as UIElement;
if (_selectedElement != null)
{
_adornerLayer = AdornerLayer.GetAdornerLayer(_selectedElement);
_adornerLayer.Add(new ResizingAdorner(_selectedElement));
if (_selectedElement.GetType() == typeof(Image) && _selectedElement.CaptureMouse())
{
_lastPosition = e.GetPosition(ContentGrid);
}
}
e.Handled = true;
}
示例7: PageFlipper
public PageFlipper(Size pageSize, UIElement hotCorner, UIElement pageHolder, FrameworkElement curlShadow, FrameworkElement dropShadow)
{
Contract.Requires(pageSize.IsValid());
m_pageSize = pageSize;
m_hotCorner = hotCorner;
m_curlShadow = curlShadow;
m_dropShadow = dropShadow;
// can be null
m_pageHolder = pageHolder;
#region helper values
m_pageHalfHeight = m_pageSize.Height * .5;
m_origin = new Point(m_pageSize.Width, m_pageSize.Height / 2.0);
m_pageDiagonal = Math.Sqrt(m_pageSize.Width * m_pageSize.Width + m_pageSize.Height * m_pageSize.Height);
m_pointLeft = new Point(-m_pageSize.Width, m_pageHalfHeight);
m_pointRight = new Point(m_pageSize.Width, m_pageHalfHeight);
#endregion
#region clips and transforms
m_pageTransformGroup = new TransformGroup();
m_pageTransformGroup.Children.Add(new TranslateTransform() { Y = -m_pageSize.Height });
m_pageTransformGroup.Children.Add(m_pageRotateTransform = new RotateTransform());
m_pageTransformGroup.Children.Add(m_pageTranslateTransform = new TranslateTransform());
m_pageHolderClip = new RectangleGeometry() { Rect = new Rect(0, 0, m_pageSize.Width, m_pageSize.Height * 2) };
m_nextPageClip = new RectangleGeometry() { Rect = new Rect(0, 0, m_pageSize.Width * 2, m_pageSize.Height * 2) };
if (m_curlShadow != null)
{
var group = new TransformGroup();
group.Children.Add(m_curlShadowRotate = new RotateTransform());
group.Children.Add(m_curlShadowTranslate = new TranslateTransform());
m_curlShadow.RenderTransform = group;
m_curlShadow.Height = m_pageDiagonal * 1.5;
m_curlShadowRotate.CenterX = m_curlShadow.Width;
m_curlShadowRotate.CenterY = m_pageDiagonal;
m_curlShadowTranslate.Y = m_pageSize.Height - m_pageDiagonal;
}
if (m_dropShadow != null)
{
//m_dropShadowBlurEffect = new BlurEffect() { Radius = 20 };
//m_dropShadow.Effect = m_dropShadowBlurEffect;
m_dropShadow.RenderTransform = m_pageTransformGroup;
m_dropShadow.Width = m_pageSize.Width;
m_dropShadow.Height = m_pageSize.Height;
}
#endregion
// MOST OF THE LOADED FUNCTION IS USED TO SET LOOK UP VALUES
// BASED ON THE pageWidth AND pageHeight INITIALLY DEFINED.
// POSITION THE PAGE AND SPINE VISUALS ACCORDINGLY
m_mouse.X = m_pageSize.Width - 1;
m_mouse.Y = m_pageHalfHeight - 1;
m_follow = m_mouse;
#region mouse handlers
if (m_hotCorner != null && m_pageHolder != null)
{
m_hotCorner.MouseMove += (sender, e) =>
{
m_animating = false;
m_listener.StartListening();
Point testBounds = (Point)e.GetPosition(m_pageHolder).Subtract(m_origin);
if (testBounds.X > m_pageSize.Width && testBounds.Y > m_pageHalfHeight)
{
m_mouse = m_pointRight;
}
else
{
m_mouse = testBounds;
}
};
m_hotCorner.MouseLeftButtonDown += (sender, e) =>
{
m_hotCorner.CaptureMouse();
};
m_hotCorner.MouseLeftButtonUp += (sender, e) =>
{
m_listener.StartListening();
m_hotCorner.ReleaseMouseCapture();
m_mouse = (m_mouse.X < 0) ? m_pointLeft : m_pointRight;
};
m_hotCorner.MouseLeave += (sender, e) =>
{
m_listener.StartListening();
m_mouse = m_pointRight;
};
}
//.........这里部分代码省略.........
示例8: BeginFluidDrag
/// <summary>
/// Handler for the event when the user starts dragging the dragElement.
/// </summary>
/// <param name="child">UIElement being dragged</param>
/// <param name="position">Position in the child where the user clicked</param>
internal void BeginFluidDrag(UIElement child, Point position)
{
if ((child == null) || (!IsComposing))
return;
// Call the event handler core on the Dispatcher. (Improves efficiency!)
Dispatcher.BeginInvoke(new Action(() =>
{
child.Opacity = DragOpacity;
child.SetValue(Canvas.ZIndexProperty, Z_INDEX_DRAG);
// Capture further mouse events
child.CaptureMouse();
dragElement = child;
lastDragElement = null;
// Since we are scaling the dragElement by DragScale, the clickPoint also shifts
dragStartPoint = new Point(position.X * DragScale, position.Y * DragScale);
}));
}
示例9: ImageFrameMouseMove
/// <summary>
/// Images the frame mouse move.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.Windows.Input.MouseEventArgs"/> instance containing the event data.</param>
private void ImageFrameMouseMove(object sender, MouseEventArgs e)
{
if (!_isDown) return;
var imagepointx = Math.Abs(e.GetPosition(this.ImageFrame).X - _startPoint.X) >
SystemParameters.MinimumHorizontalDragDistance;
var imagepointy = Math.Abs(e.GetPosition(this.ImageFrame).Y - _startPoint.Y) >
SystemParameters.MinimumVerticalDragDistance;
if (_isDragging || (!imagepointx && !imagepointy)) return;
_isDragging = true;
_realDragSource = e.Source as UIElement;
if (_realDragSource != null)
_realDragSource.CaptureMouse();
DragDrop.DoDragDrop(_dummyDragSource, new DataObject(DragElementName, e.Source, true),
DragDropEffects.Move);
}
示例10: DoDragDropSimulate
public void DoDragDropSimulate(IDataObject dataObject, UIElement dragSource, bool showDragVisual, bool useVisualBrush, DragDropEffects effects, Action callback)
{
if (!IsDragging)
{
_dataObject = dataObject;
_callback = callback;
_useDefaultCursor = true;
_dragScope = Application.Current.MainWindow.Content as FrameworkElement;
_previousDrop = _dragScope.AllowDrop;
_dragScope.AllowDrop = true;
_dragScope.PreviewMouseLeftButtonUp += DragScope_PreviewMouseLeftButtonUp;
_dragScope.MouseMove += DragScope_MouseMove;
_dragScope.PreviewKeyDown += DragScope_PreviewKeyDown;
_layer = AdornerLayer.GetAdornerLayer(_dragScope);
if (showDragVisual)
{
_dragAdorner = new DragAdorner(_dragScope, dragSource, useVisualBrush);
_layer.Add(_dragAdorner);
_dragAdorner.UpdatePosition(Mouse.GetPosition(_dragScope), true);
}
_dragSource = dragSource;
IsDragging = true;
_dragHasLeftScope = false;
Mouse.OverrideCursor = Cursors.No;
dragSource.CaptureMouse();
}
}