private void BlockItemDrag_MouseMove(object sender, MouseEventArgs e) { if (dragged != null) { Mouse.OverrideCursor = Cursors.None; } if (e.LeftButton == MouseButtonState.Pressed && dragged == null) { #if DEBUG Log.Info("Item drop."); #endif Mouse.AddMouseMoveHandler(this, Item_MouseMove); Mouse.AddMouseUpHandler(this, Item_MouseRelease); var p = e.GetPosition(this); drag.Margin = new Thickness(p.X - 24, p.Y - 24, 0, 0); var img = sender as Image; drag.Source = img.Source; Mouse.OverrideCursor = Cursors.No; drag.Visibility = Visibility.Visible; var item = img.Tag as Item; foreach (var v in data.Selected.Blocks) { v.Items.Remove(item); } dragged = data.Items.Data.Values.FirstOrDefault(s => s.Id.Equals(item.Id + "")); } }
public InputDeviceHelper(DependencyObject context) { if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) { throw new InvalidOperationException("The calling thread must be STA!"); } Dispatcher = Dispatcher.CurrentDispatcher; var keys = Enum.GetValues(typeof(Key)).Cast <Key>().ToArray(); _kbState = new Dictionary <Key, bool>(keys.Length); foreach (var key in keys) { _kbState[key] = false; } var mouseButtons = Enum.GetValues(typeof(MouseButton)).Cast <MouseButton>().ToArray(); _mbState = new Dictionary <MouseButton, bool>(mouseButtons.Length); foreach (var button in mouseButtons) { _mbState[button] = false; } Keyboard.AddKeyUpHandler(context, OnKeyStateChanged); Keyboard.AddKeyDownHandler(context, OnKeyStateChanged); Keyboard.AddLostKeyboardFocusHandler(context, OnKeyboardFocusChanged); Mouse.AddMouseUpHandler(context, OnMouseButtonStateChanged); Mouse.AddMouseDownHandler(context, OnMouseButtonStateChanged); }
public static IObservable <MouseButtonEventArgs> MouseUp(this DependencyObject that) { return(Observable.FromEvent <MouseButtonEventArgs>( on => Mouse.AddMouseUpHandler(that, (o, e) => on(e)), on => Mouse.RemoveMouseUpHandler(that, (o, e) => on(e)) )); }
protected override void OnPlotterAttached(Plotter plotter) { base.OnPlotterAttached(plotter); Mouse.AddMouseDownHandler(Parent, OnMouseDown); Mouse.AddMouseMoveHandler(Parent, OnMouseMove); Mouse.AddMouseUpHandler(Parent, OnMouseUp); Mouse.AddMouseWheelHandler(Parent, OnMouseWheel); }
private void BindToPhysicalMouse(MouseButtonEventArgs args) { topElement = Target.Parents().OfType <IInputElement>().Last(); topElement.CaptureMouse(); buttonBeingDragged = args.ChangedButton; topElement.MouseMove += OnMouseMoved; if (topElement is DependencyObject moveSource) { Mouse.AddMouseUpHandler(moveSource, MouseUp); } initialArgs = args; }
public void SetToolType(DrawToolType type) { Mouse.RemoveMouseDownHandler(this.DrawCanvas, this.polylineToolMouseDown); Mouse.RemoveMouseUpHandler(this, this.polylineToolMouseUp); Mouse.RemoveMouseMoveHandler(this, this.polylineToolMouseMove); this.DrawCanvas.Cursor = null; this.lastShape = null; this.ToolType = type; Mouse.AddMouseDownHandler(this.DrawCanvas, this.polylineToolMouseDown); Mouse.AddMouseUpHandler(this, this.polylineToolMouseUp); Mouse.AddMouseMoveHandler(this, this.polylineToolMouseMove); this.DrawCanvas.Cursor = Cursors.Cross; }
protected override void OnViewportChanged() { base.OnViewportChanged(); //Mouse.AddPreviewMouseDownHandler(Parent, (MouseButtonEventHandler)OnMouseDown); //Mouse.AddPreviewMouseMoveHandler(Parent, (MouseEventHandler)OnMouseMove); //Mouse.AddPreviewMouseUpHandler(Parent, (MouseButtonEventHandler)OnMouseUp); Mouse.AddMouseDownHandler(Parent, OnMouseDown); Mouse.AddMouseMoveHandler(Parent, OnMouseMove); Mouse.AddMouseUpHandler(Parent, OnMouseUp); Mouse.AddMouseWheelHandler(Parent, OnMouseWheel); }
/// <summary> /// Gets the surrounding textview and adds the mouse handler. /// </summary> private void OnLoaded(object sender, RoutedEventArgs e) { DependencyObject current = this; while (!(current is IWpfTextView) && current != null) { current = VisualTreeHelper.GetParent(current); } _textView = (current as IWpfTextView)?.VisualElement ?? current; Mouse.AddMouseUpHandler(_textView, OnMouseUp); Mouse.AddPreviewMouseDownHandler(_textView, OnPreviewMouseDown); }
public PreviewViewVM(IApplicationCommands applicationCommands) { _applicationCommands = applicationCommands; using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) { _dpiX = g.DpiX; _dpiY = g.DpiY; } foreach (Window window in Application.Current.Windows) { Mouse.AddMouseUpHandler(window, new MouseButtonEventHandler(MouseUpEvent)); Keyboard.AddPreviewKeyUpHandler(window, new KeyEventHandler(KeyUpEvent)); } _timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1.5) }; _timer.Tick += Timer_Tick; }
private void ItemDrag_MouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed && dragged == null) { #if DEBUG Log.Info("Item drag."); #endif Mouse.AddMouseMoveHandler(this, Item_MouseMove); Mouse.AddMouseUpHandler(this, Item_MouseRelease); var p = e.GetPosition(this); drag.Margin = new Thickness(p.X - 24, p.Y - 24, 0, 0); var img = sender as Image; drag.Source = img.Source; Mouse.OverrideCursor = Cursors.No; drag.Visibility = Visibility.Visible; dragged = img.Tag as ItemData; } }
public virtual void AddHandler() { Mouse.AddMouseDownHandler(this.CurrentWindow.pictureBox, MouseDownHandler); Mouse.AddMouseUpHandler(this.CurrentWindow.pictureBox, MouseUpHandler); Mouse.AddMouseMoveHandler(this.CurrentWindow.pictureBox, MouseMoveHandler); }
public virtual void ConnectHandle() { Mouse.AddMouseDownHandler(this.CurrentWindow.Canvas, MouseDownHandle); Mouse.AddMouseUpHandler(this.CurrentWindow.Canvas, MouseUpHandle); Mouse.AddMouseMoveHandler(this.CurrentWindow.Canvas, MouseMoveHandler); }
/// <summary> /// Отвязка и привязка событий к мыше и клавиатуре в зависимости от выбранного типа интрумента /// </summary> public void SetToolType(DrawToolType type) { switch (this.ToolType) { case DrawToolType.Pointer: Mouse.RemoveMouseDownHandler(this.window, this.toolMouseDown); Mouse.RemoveMouseUpHandler(this.window, this.toolMouseUp); Mouse.RemoveMouseMoveHandler(this.window, this.toolMouseMove); Keyboard.RemoveKeyDownHandler(this.window, this.toolKeyDown); Keyboard.RemoveKeyUpHandler(this.window, this.toolKeyUp); Mouse.RemoveMouseDownHandler(this.dotsControl, this.dotsControl_MouseDown); Mouse.RemoveMouseUpHandler(this.dotsControl, this.dotsControl_MouseUp); Mouse.RemoveMouseMoveHandler(this.dotsControl, this.dotsControl_MouseMove); this.selectShapes(null); break; case DrawToolType.Polyline: Mouse.RemoveMouseDownHandler(this.canvas, this.polylineToolMouseDown); Mouse.RemoveMouseUpHandler(this.window, this.polylineToolMouseUp); Mouse.RemoveMouseMoveHandler(this.window, this.polylineToolMouseMove); this.canvas.Cursor = null; this.lastShape = null; break; case DrawToolType.Rectangle: Mouse.RemoveMouseDownHandler(this.canvas, this.rectangleToolMouseDown); Mouse.RemoveMouseUpHandler(this.window, this.rectangleToolMouseMouseUp); Mouse.RemoveMouseMoveHandler(this.window, this.rectangleToolMouseMove); this.canvas.Cursor = null; this.lastShape = null; break; case DrawToolType.Delete: Mouse.RemoveMouseDownHandler(this.canvas, this.deleteToolMouseDown); Mouse.RemoveMouseMoveHandler(this.window, this.deleteToolMouseMove); if (this.lastShape != null) { this.lastShape.SetDeletingStyle(false); this.lastShape = null; } break; } this.ToolType = type; switch (this.ToolType) { case DrawToolType.Pointer: Mouse.AddMouseDownHandler(this.dotsControl, this.dotsControl_MouseDown); Mouse.AddMouseUpHandler(this.dotsControl, this.dotsControl_MouseUp); Mouse.AddMouseDownHandler(this.window, this.toolMouseDown); Mouse.AddMouseUpHandler(this.window, this.toolMouseUp); Mouse.AddMouseMoveHandler(this.window, this.toolMouseMove); Mouse.AddMouseMoveHandler(this.dotsControl, this.dotsControl_MouseMove); Keyboard.AddKeyDownHandler(this.window, this.toolKeyDown); Keyboard.AddKeyUpHandler(this.window, this.toolKeyUp); break; case DrawToolType.Polyline: Mouse.AddMouseDownHandler(this.canvas, this.polylineToolMouseDown); Mouse.AddMouseUpHandler(this.window, this.polylineToolMouseUp); Mouse.AddMouseMoveHandler(this.window, this.polylineToolMouseMove); this.canvas.Cursor = Cursors.Cross; break; case DrawToolType.Rectangle: Mouse.AddMouseDownHandler(this.canvas, this.rectangleToolMouseDown); Mouse.AddMouseUpHandler(this.window, this.rectangleToolMouseMouseUp); Mouse.AddMouseMoveHandler(this.window, this.rectangleToolMouseMove); this.canvas.Cursor = Cursors.Cross; break; case DrawToolType.Delete: Mouse.AddMouseDownHandler(this.canvas, this.deleteToolMouseDown); Mouse.AddMouseMoveHandler(this.window, this.deleteToolMouseMove); break; } }
/// <summary> Starts the listening of mouse events. /// </summary> public void StartMouseListening() { Mouse.AddMouseDownHandler(_renderer, _controller.MouseDownHandler); Mouse.AddMouseUpHandler(_renderer, _controller.MouseUpHandler); Mouse.AddMouseMoveHandler(_renderer, _controller.MouseMoveHandler); }
protected override void OnAttached() { base.OnAttached(); Mouse.AddMouseUpHandler(AssociatedObject, Handler); }
private void BindToMouse() { CaptureHost.CaptureMouse(); Mouse.AddMouseMoveHandler(clickSource, SendMouseMove); Mouse.AddMouseUpHandler(clickSource, SendMouseUp); }