/// <summary> /// Return wheter the mouse is over a control /// </summary> /// <param name="s"></param> /// <param name="e"></param> /// <returns>True if the mouse is over a control, false otherwise</returns> internal static bool IsMouseOver(FrameworkElement s, System.Windows.Input.MouseEventArgs e) { Rect bounds = new Rect(0, 0, s.ActualWidth, s.ActualHeight); if (bounds.Contains(e.GetPosition(s))) return true; return false; }
protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e) { content.Focus(); Keyboard.Focus(content); mouseButtonDown = e.ChangedButton; origZoomAndPanControlMouseDownPoint = e.GetPosition(this); origContentMouseDownPoint = e.GetPosition(content); if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0 && (e.ChangedButton == MouseButton.Left || e.ChangedButton == MouseButton.Right)) { // Shift + left- or right-down initiates zooming mode. mouseHandlingMode = MouseHandlingMode.Zooming; } else if (mouseButtonDown == MouseButton.Left) { // Just a plain old left-down initiates panning mode. mouseHandlingMode = MouseHandlingMode.Panning; } if (mouseHandlingMode != MouseHandlingMode.None) { // Capture the mouse so that we eventually receive the mouse up event. this.CaptureMouse(); e.Handled = true; } base.OnMouseDown(e); }
private void Window_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { if (this.isMouseDown) { double curx = e.GetPosition(null).X; double cury = e.GetPosition(null).Y; System.Windows.Shapes.Rectangle r = new System.Windows.Shapes.Rectangle(); SolidColorBrush brush = new SolidColorBrush(Colors.White); r.Stroke = brush; r.Fill = brush; r.StrokeThickness = 1; r.Width = Math.Abs(curx - x); r.Height = Math.Abs(cury - y); cnv.Children.Clear(); cnv.Children.Add(r); Canvas.SetLeft(r, Math.Min(x , curx)); Canvas.SetTop(r, Math.Min(y, cury)); if (e.LeftButton == MouseButtonState.Released) { cnv.Children.Clear(); width = Math.Abs(curx - x); height = Math.Abs(cury - y); bitmap = ScreenShotMaker.CaptureScreen(width, height, Math.Min(x, curx) - 7, Math.Min(y, cury) - 7); this.x = this.y = 0; this.isMouseDown = false; this.Close(); } } }
void map_Tap(object sender, System.Windows.Input.GestureEventArgs e) { layer.Children.Clear(); layer.AddChild(Pin_My, map.ViewportPointToLocation(e.GetPosition(map))); Pin_My.Tag = map.ViewportPointToLocation(e.GetPosition(map)); }
private void lbl_MouseMove(Object sender, System.Windows.Input.MouseEventArgs e) { if (Selected) { Canvas.SetLeft(sender as Button, e.GetPosition((sender as Button).Parent as FrameworkElement).X); Canvas.SetTop(sender as Button, e.GetPosition((sender as Button).Parent as FrameworkElement).Y); } }
private void Element_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { if (!isdrag) return; var control = (sender as UIElement); control.SetValue(Canvas.LeftProperty, e.GetPosition(container).X - control.DesiredSize.Width / 2); control.SetValue(Canvas.TopProperty, e.GetPosition(container).Y - control.DesiredSize.Height / 2); var vector = VisualTreeHelper.GetOffset(control); }
private void Picture_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (!WritingFlag) { this.textXlock.Text = e.GetPosition(Picture).X.ToString(); this.textYlock.Text = e.GetPosition(Picture).Y.ToString(); } }
private void window_Resize(object sender, System.Windows.Input.MouseEventArgs e) { Rectangle rect = (Rectangle)sender; Window win = (Window)rect.TemplatedParent; if (isResizing) { rect.CaptureMouse(); if (resizeType == ResizeType.Width) win.Width = e.GetPosition(win).X + 5; if (resizeType == ResizeType.Height) win.Height = e.GetPosition(win).Y + 5; } }
private void DragScrollGrid_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { if (!IsMouseCaptured) return; if ((int)_lastPosition.X == (int)e.GetPosition(this).X) return; if (_lastPosition.X > e.GetPosition(this).X) { //To the Left. //Value--; } //To the right. //Value++; }
void LineString_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (DrawControl.LinesPointsLayer.Visibility == Visibility.Visible) { double min_distance = 10000; int insert_index = 0; Point _CurrentMousePoint = MapInstance.CoordHelper.PixelToGeo(e.GetPosition(MapInstance)); for (int j = 0; j < this.Points.Count - 1; j++) { if (min_distance > Math.Abs(GetDistance(Points[j], Points[j + 1]) - GetDistance(Points[j], _CurrentMousePoint) - GetDistance(Points[j + 1], _CurrentMousePoint))) { min_distance = Math.Abs(GetDistance(Points[j], Points[j + 1]) - GetDistance(Points[j], _CurrentMousePoint) - GetDistance(Points[j + 1], _CurrentMousePoint)); insert_index = j + 1; } } Points.Insert(insert_index, _CurrentMousePoint); DrawControl.LinesPointsLayer.Add(new DrawPoint { Point = _CurrentMousePoint, LineString = this, Index = insert_index }); for (int i = 0; i < DrawControl.LinesPointsLayer.Children.Count - 1; i++) { if ((DrawControl.LinesPointsLayer.Children[i] as DrawPoint).LineString == this) { if ((DrawControl.LinesPointsLayer.Children[i] as DrawPoint).Index >= insert_index) (DrawControl.LinesPointsLayer.Children[i] as DrawPoint).Index++; } } } }
void focus_Tapped(object sender, System.Windows.Input.GestureEventArgs e) { if (_phoneCamera != null) { if (_phoneCamera.IsFocusAtPointSupported == true) { // Determine the location of the tap. Point tapLocation = e.GetPosition(viewfinderCanvas); // Position the focus brackets with the estimated offsets. focusBrackets.SetValue(Canvas.LeftProperty, tapLocation.X - 30); focusBrackets.SetValue(Canvas.TopProperty, tapLocation.Y - 28); // Determine the focus point. double focusXPercentage = tapLocation.X / viewfinderCanvas.ActualWidth; double focusYPercentage = tapLocation.Y / viewfinderCanvas.ActualHeight; // Show the focus brackets and focus at point. try { focusBrackets.Visibility = Visibility.Visible; _phoneCamera.FocusAtPoint(focusXPercentage, focusYPercentage); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
public override void OnMouseMove(System.Windows.Controls.InkCanvas inkCanvas, System.Windows.Input.MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { bottomRight = e.GetPosition(inkCanvas); if(topLeft != bottomRight) { StylusPointCollection pts = new StylusPointCollection(); GetRectangle(pts, (s) => { if (StrokeResult != null) inkCanvas.Strokes.Remove(StrokeResult); DrawingAttributes drawingAttributes = new DrawingAttributes { Color = inkCanvas.DefaultDrawingAttributes.Color, Width = inkCanvas.DefaultDrawingAttributes.Width, StylusTip = StylusTip.Ellipse, IgnorePressure = true, FitToCurve = true }; var BackgroundColor = inkCanvas.DefaultDrawingAttributes.GetPropertyData(DrawAttributesGuid.BackgroundColor); drawingAttributes.AddPropertyData(DrawAttributesGuid.BackgroundColor, BackgroundColor); StrokeResult = new RectangleStroke(s, drawingAttributes); inkCanvas.Strokes.Add(StrokeResult); } ); } } }
private void Window_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { Point p = e.GetPosition(this); posX = p.X; // private double posX is a class member posY = p.Y; // private double posY is a class member }
private void Canvas_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed) { var canvas = (Canvas)sender; var pos = e.GetPosition(canvas); var left = Canvas.GetLeft(rect); var top = Canvas.GetTop(rect); var width = pos.X - left; var height = pos.Y - top; if (height > 0 && width > 0) { rect.Width = width; rect.Height = height; } txtHeight.Text = height.ToString(); txtWidth.Text = width.ToString(); txtXPosition.Text = left.ToString(); txtYPosition.Text = top.ToString(); } }
private new void MouseHover(object sender, System.Windows.Input.MouseEventArgs e) { var pos = codeEditor.TextArea.TextView.GetPositionFloor(e.GetPosition(codeEditor.TextArea.TextView) + codeEditor.TextArea.TextView.ScrollOffset); bool inDocument = pos.HasValue; if (inDocument) { TextLocation logicalPosition = pos.Value.Location; int offset = codeEditor.Document.GetOffset(logicalPosition); var markersAtOffset = textMarkerService.GetMarkersAtOffset(offset); TextMarkerService.TextMarker markerWithToolTip = markersAtOffset.FirstOrDefault(marker => marker.ToolTip != null); if (markerWithToolTip != null) { if (toolTip == null) { toolTip = new System.Windows.Controls.ToolTip(); toolTip.Closed += ToolTipClosed; // toolTip.PlacementTarget = this; toolTip.Content = new System.Windows.Controls.TextBlock { Text = markerWithToolTip.ToolTip, TextWrapping = System.Windows.TextWrapping.Wrap }; toolTip.IsOpen = true; e.Handled = true; } } } }
private void frame_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { // Warning!!: Keep these values in sync with the .vsct file const string guidVSPackageContextMenuCmdSet = "c1a3a312-e25a-4cd1-b557-011428323a99"; const int MyContextMenuId = 0x0200; System.IServiceProvider serviceProvider; IVsUIShell uiShell; System.Guid contextMenuGuid = new System.Guid(guidVSPackageContextMenuCmdSet); System.Windows.Point relativePoint; System.Windows.Point screenPoint; POINTS point; POINTS[] points; if (e.ChangedButton == System.Windows.Input.MouseButton.Right) { serviceProvider = (System.IServiceProvider)m_package; uiShell = serviceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell; if (uiShell != null) { relativePoint = e.GetPosition(this); screenPoint = this.PointToScreen(relativePoint); point = new POINTS(); point.x = (short)screenPoint.X; point.y = (short)screenPoint.Y; points = new[] { point }; // TODO: error handling uiShell.ShowContextMenu(0, ref contextMenuGuid, MyContextMenuId, points, null); } } }
public override void PostprocessMouseMove(System.Windows.Input.MouseEventArgs e) { try { if (this._isMouseDown && (e.RightButton == System.Windows.Input.MouseButtonState.Pressed)) { string lineColor = Umc.Core.Tools.VSGesture.Services.VSGestureService.Current.VSGestureInfo.UserSettings.LineColor; string lineThickness = Umc.Core.Tools.VSGesture.Services.VSGestureService.Current.VSGestureInfo.UserSettings.LineThickness; string[] strArray = lineColor.Split(new char[] { ',' }); Point position = e.GetPosition(this._view.VisualElement); Brush brush = new SolidColorBrush(Color.FromRgb(byte.Parse(strArray[0]), byte.Parse(strArray[1]), byte.Parse(strArray[2]))); this._analyzer.Add(new System.Windows.Input.StylusPoint(position.X, position.Y)); this._layer = this._view.GetAdornmentLayer("VSGestureWindow"); var adornment = new System.Windows.Shapes.Line { X1 = this._preX, Y1 = this._preY, X2 = position.X + this._view.ViewportLeft, Y2 = position.Y + this._view.ViewportTop, StrokeThickness = (float)((Umc.Core.Tools.VSGesture.Controls.LineThicknessStyle)Enum.Parse(typeof(Umc.Core.Tools.VSGesture.Controls.LineThicknessStyle), lineThickness)), Stroke = brush }; this._layer.AddAdornment(AdornmentPositioningBehavior.ViewportRelative, null, null, adornment, null); this._preX = position.X + this._view.ViewportLeft; this._preY = position.Y + this._view.ViewportTop; } } catch (Exception exception) { MessageBox.Show(exception.Message); } base.PostprocessMouseMove(e); }
public override void OnMouseMove(InkCanvas inkCanvas, System.Windows.Input.MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { endPoint = e.GetPosition(inkCanvas); if (startPoint != endPoint) { StylusPointCollection pts = new StylusPointCollection(); GetLine(pts, (s) => { if (StrokeResult != null) inkCanvas.Strokes.Remove(StrokeResult); DrawingAttributes drawingAttributes = new DrawingAttributes { Color = inkCanvas.DefaultDrawingAttributes.Color, Width = inkCanvas.DefaultDrawingAttributes.Width, StylusTip = StylusTip.Ellipse, IgnorePressure = true, FitToCurve = true }; StrokeResult = new ArrowLineStroke(s, drawingAttributes); inkCanvas.Strokes.Add(StrokeResult); } ); } } }
//Handles movement of mouse if actively drawing public void DoDraw(System.Windows.Input.MouseEventArgs e) { if (Drawing) { updatePixelColor(e.GetPosition(this), MainWindow.ActiveBrushColor); } }
private void UpdateLastMousePosition(object sender, System.Windows.Input.MouseEventArgs e) { if (_parentCanvas == null) return; _parentLastMousePosition = e.GetPosition(_parentCanvas); }
private void SurfaceOnMouseMove(object sender, System.Windows.Input.MouseEventArgs e) { if (isMouseLeftMouseButtonPressed && this.ApplicationViewModel.Image != null) { var currentMousePosition = e.GetPosition(surface); if (this.previousMouseDownPosition.X - currentMousePosition.X > 0) { this.ApplicationViewModel.Image.RotationYAngle -= RotationDelta; } if (this.previousMouseDownPosition.X - currentMousePosition.X < 0) { this.ApplicationViewModel.Image.RotationYAngle += RotationDelta; } if (this.previousMouseDownPosition.Y - currentMousePosition.Y > 0) { this.ApplicationViewModel.Image.RotationXAngle -= RotationDelta; } if (this.previousMouseDownPosition.Y - currentMousePosition.Y < 0) { this.ApplicationViewModel.Image.RotationXAngle += RotationDelta; } previousMouseDownPosition = currentMousePosition; } }
public void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, System.Windows.Input.MouseEventArgs e) { var createdItem = CreateItem(panel.Context, createItemType); var startPoint = e.GetPosition(clickedOn.View); var operation = PlacementOperation.TryStartInsertNewComponents(clickedOn, new DesignItem[] { createdItem }, new Rect[] { new Rect(startPoint.X, startPoint.Y, double.NaN, double.NaN) }, PlacementType.AddItem); if (operation != null) { createdItem.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem }); operation.Commit(); } createdItem.Properties[Shape.StrokeProperty].SetValue(Brushes.Black); createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d); createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None); if (createItemType == typeof(Polyline)) createdItem.Properties[Polyline.PointsProperty].CollectionElements.Add(createdItem.Services.Component.RegisterComponentForDesigner(new Point(0,0))); else createdItem.Properties[Polygon.PointsProperty].CollectionElements.Add(createdItem.Services.Component.RegisterComponentForDesigner(new Point(0,0))); new DrawPolylineMouseGesture(createdItem, clickedOn.View, changeGroup).Start(panel, (MouseButtonEventArgs) e); }
public void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, System.Windows.Input.MouseEventArgs e) { var createdItem = CreateItem(panel.Context, createItemType); var startPoint = e.GetPosition(clickedOn.View); var operation = PlacementOperation.TryStartInsertNewComponents(clickedOn, new DesignItem[] { createdItem }, new Rect[] { new Rect(startPoint.X, startPoint.Y, double.NaN, double.NaN) }, PlacementType.AddItem); if (operation != null) { createdItem.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem }); operation.Commit(); } createdItem.Properties[Shape.StrokeProperty].SetValue(Brushes.Black); createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d); createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None); var figure = new PathFigure(); var geometry = new PathGeometry(); var geometryDesignItem = createdItem.Services.Component.RegisterComponentForDesigner(geometry); var figureDesignItem = createdItem.Services.Component.RegisterComponentForDesigner(figure); createdItem.Properties[Path.DataProperty].SetValue(geometry); //geometryDesignItem.Properties[PathGeometry.FiguresProperty].CollectionElements.Add(figureDesignItem); figureDesignItem.Properties[PathFigure.StartPointProperty].SetValue(new Point(0,0)); new DrawPathMouseGesture(figure, createdItem, clickedOn.View, changeGroup, this.ExtendedItem.GetCompleteAppliedTransformationToView()).Start(panel, (MouseButtonEventArgs) e); }
private void checkedListBox_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { string eventText = "Index from point: "; int index = this.checkedListBoxOne.IndexFromPoint(e.GetPosition(this.checkedListBoxOne)); eventText += index + "\n"; this.UpdateLog(eventText); }
public override void OnMouseMove(InkCanvas inkCanvas, System.Windows.Input.MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { var p = e.GetPosition(inkCanvas); if (p != point) { point = p; GetBrush(pts, (s) => { if (StrokeResult != null) inkCanvas.Strokes.Remove(StrokeResult); DrawingAttributes drawingAttributes = new DrawingAttributes { Color = inkCanvas.DefaultDrawingAttributes.Color, Width = inkCanvas.DefaultDrawingAttributes.Width, StylusTip = StylusTip.Ellipse, IgnorePressure = true, FitToCurve = true }; StrokeResult = new BrushStroke(s, drawingAttributes); inkCanvas.Strokes.Add(StrokeResult); } ); } } }
void _zoomControl_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { if(_edgeBp == null) return; var pos = _zoomControl.TranslatePoint(e.GetPosition(_zoomControl), _graphArea); pos.Offset(2, 2); _edgeBp.UpdateTargetPosition(pos); }
void Page_Taped(object sender, System.Windows.Input.GestureEventArgs e) { if (Menu.Visibility == System.Windows.Visibility.Visible) { Menu.Visibility = System.Windows.Visibility.Collapsed; return; } var pos = e.GetPosition(this); var col = (int)(pos.X * 3 / this.ActualWidth); var row = (int)(pos.Y * 3 / this.ActualHeight); if(col == 2 || row == 2) { //ListBox.Panel.LineUp(); //ListBox.Panel.PageDown(); //ListBox.Panel.SetVerticalOffset(ListBox.Panel.VerticalOffset + 1.62); } else if (col == 0 || row == 0) { //ListBox.Panel.LineDown(); //ListBox.Panel.PageUp(); //ListBox.Panel.SetVerticalOffset(ListBox.Panel.VerticalOffset - 1.62); } else { Menu.Visibility = System.Windows.Visibility.Visible; } }
private void Image_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { var AssociatedObject = this; // Retrieve the coordinate of the mouse position in relation to the supplied image. Point point = e.GetPosition(AssociatedObject); // Use RenderTargetBitmap to get the visual, in case the image has been transformed. var renderTargetBitmap = new RenderTargetBitmap((int) AssociatedObject.ActualWidth, (int) AssociatedObject.ActualHeight, 96, 96, PixelFormats.Default); renderTargetBitmap.Render(AssociatedObject); // Make sure that the point is within the dimensions of the image. if ((point.X <= renderTargetBitmap.PixelWidth) && (point.Y <= renderTargetBitmap.PixelHeight)) { // Create a cropped image at the supplied point coordinates. var croppedBitmap = new CroppedBitmap(renderTargetBitmap, new Int32Rect((int) point.X, (int) point.Y, 1, 1)); // Copy the sampled pixel to a byte array. var pixels = new byte[4]; croppedBitmap.CopyPixels(pixels, 4, 0); // Assign the sampled color to a SolidColorBrush and return as conversion. var SelectedColor = Color.FromArgb(255, pixels[2], pixels[1], pixels[0]); TextBox.Text = "#" + SelectedColor.ToString().Substring(3); Label.Background = new SolidColorBrush(SelectedColor); } }
private void bCanvas_MouseLeftButtonDown_1(object sender, System.Windows.Input.MouseButtonEventArgs e) { puntero = e.GetPosition(bGridMain); posicionx = (int)puntero.X / 100; posiciony = (int)puntero.Y / 100; muestra.Text = posicionx.ToString(); }
void MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (e.ClickCount > 1) return; // Ignore double(and so on)-clicks this.handle.CaptureMouse(); this.lastPoint = e.GetPosition(null); this.Dragging = true; }