static void target_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var target = sender as FrameworkElement; if (null == target) { return; } var scroller = FindVisualParent <ScrollViewer> (target); if (null == scroller) { Trace.WriteLine("Control should be placed inside ScrollViewer for drag scrolling to work"); return; } _captures[sender] = new MouseCapture { HorizontalOffset = scroller.HorizontalOffset, VerticalOffset = scroller.VerticalOffset, Point = e.GetPosition(scroller), }; var cursor = target.GetValue(DraggingCursorProperty) as Cursor; if (cursor != null) { Mouse.OverrideCursor = cursor; } }
static void target_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var target = sender as ScrollViewer; if (target == null) return; _captures[sender] = new MouseCapture { VerticalOffset = target.VerticalOffset, Point = e.GetPosition(target), }; }
static void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var target = sender as ScrollViewer; if (target == null) return; _captures[sender] = new MouseCapture { HorizontalOffset = target.HorizontalOffset, Point = e.GetPosition(target), }; }
private static void target_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var target = sender as ScrollViewer; if (target == null) return; if (Mouse.DirectlyOver as Canvas == null) return; Captures[sender] = new MouseCapture { VerticalOffset = target.VerticalOffset, HorizontalOffset = target.HorizontalOffset, Point = e.GetPosition(target), }; }
private static void TargetPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var target = sender as ScrollViewer; if (target != null) { _captures[sender] = new MouseCapture { HorizontalOffset = target.HorizontalOffset, VerticalOffset = target.VerticalOffset, Point = e.GetPosition(target), }; _isTargetUnloaded = false; } }
static void target_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var target = sender as ScrollViewer; if (target == null) { return; } _captures[sender] = new MouseCapture { VerticalOffset = target.VerticalOffset, HorizontalOffset = target.HorizontalOffset, Point = e.GetPosition(target), }; Mouse.OverrideCursor = Cursors.Hand; }
private static void target_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var target = sender as ScrollViewer; if (target == null) { return; } if (Mouse.DirectlyOver as Canvas == null) { return; } Captures[sender] = new MouseCapture { VerticalOffset = target.VerticalOffset, HorizontalOffset = target.HorizontalOffset, Point = e.GetPosition(target), }; }
private void tmrMouseLeave_Tick(System.Object sender, System.EventArgs e) { Point scrPT = Control.MousePosition; Point ctlPT = this.PointToClient(scrPT); if (ctlPT.X < 0 || ctlPT.Y < 0 || ctlPT.X > this.Width || ctlPT.Y > this.Height) { // Stop timer if (m_ButtonState != ButtonState.ButtonDown) { tmrMouseLeave.Stop(); } m_MouseState = MouseCapture.Outside; Refresh(); } else { m_MouseState = MouseCapture.Inside; Refresh(); } }
private void tmrMouseLeave_Tick(System.Object sender, System.EventArgs e) { var scrPT = Control.MousePosition; Point ctlPT = this.PointToClient(scrPT); if (Song == "2") { Debug.WriteLine(scrPT.X + "," + scrPT.Y + "\t" + ctlPT.X + "," + ctlPT.Y); } if (ctlPT.X <0 | ctlPT.Y <0 | ctlPT.X> this.Width | ctlPT.Y> this.Height) { // Stop timer _tmrMouseLeave.Stop(); bMouse = MouseCapture.Outside; Refresh(); } else { bMouse = MouseCapture.Inside; } }
private void tmrMouseLeave_Tick(object sender, EventArgs e) { try { var scrPT = MousePosition; Point ctlPT = PointToClient(scrPT); if (ctlPT.X <0 | ctlPT.Y <0 | ctlPT.X> Width | ctlPT.Y> Height) { //Stop timer TmrMouseLeave.Stop(); _bMouse = MouseCapture.Outside; Refresh(); } else { _bMouse = MouseCapture.Inside; } } catch (Exception) { //Item has already been disposed } }
public override void InitLevel() { _mouseCapture = new MouseCapture(_playGrid); _xMaxBounds = (int)_playGrid.ActualWidth - 60; _xMinBounds = 10; _yMaxBounds = (int)_playGrid.ActualHeight - 60; _yMinBounds = 10; _unitsHit = 0; _nonMovingUnits = new List <Unit>(); _movingUnits = new List <MovingUnit>(); // set trees for (int t = 0; t < this.NonMovingUnitAmount; t++) { Application.Current.Dispatcher.Invoke(() => { // set location // random based on x and y bounds var xPos = (double)_random.Next(_xMinBounds, _xMaxBounds); var yPos = (double)_random.Next(_yMinBounds, _yMaxBounds); // Set tree on screen Unit unit = UnitFactory.CreateUnit(UnitEnum.Tree, xPos, yPos); _nonMovingUnits.Add(unit); }); } // random amount MovingUnits int startAmountUnits = _random.Next(5); for (int x = 0; x < startAmountUnits; x++) { Application.Current.Dispatcher.Invoke(() => { MovingUnit unit = null; bool collides = true; while (collides) { // set location var xPos = _random.Next(_xMinBounds, _xMaxBounds); var yPos = _random.Next(_yMinBounds, _yMaxBounds); var unitType = (UnitEnum)_random.Next(2, 4); unit = (MovingUnit)UnitFactory.CreateUnit(unitType, xPos, yPos); if ( !_nonMovingUnits.Any( unit1 => xPos >= unit1.LeftPosition && xPos <= (unit1.LeftPosition + 50) && yPos >= unit1.TopPosition && yPos <= (unit1.TopPosition + 50))) { collides = false; } } unit.SetSteps(this.MinSpeed, this.MaxSpeed); _movingUnits.Add(unit); }); } }
public void UpdateUnits() { Dictionary <double, double> clickedLocations = MouseCapture.getClicks(); foreach (MovingUnit unit in _movingUnits) { foreach (KeyValuePair <double, double> coords in clickedLocations) { unit.SetIsShot(coords); } unit.IsOutOfBounds(_yMaxBounds, _xMaxBounds); bool wasCollide = false; unit.MoveX(); foreach (Unit nonMovingUnit in _nonMovingUnits) { wasCollide = unit.CheckCollisionX(nonMovingUnit); } unit.MoveY(); if (!wasCollide) { foreach (Unit nonMovingUnit in _nonMovingUnits) { unit.CheckCollisionY(nonMovingUnit); } } } MovingUnit newMovingUnit = null; // Add MovingUnit int randomNum = _random.Next(35); if (randomNum % 2 == 0 && _movingUnits.Count < this.MovingUnitAmount) { bool collides = true; while (collides) { // set location var xPos = _random.Next(_xMinBounds, _xMaxBounds); var yPos = _random.Next(_yMinBounds, _yMaxBounds); var unitType = (UnitEnum)_random.Next(2, 4); newMovingUnit = (MovingUnit)UnitFactory.CreateUnit(unitType, xPos, yPos); if ( !_nonMovingUnits.Any( unit1 => xPos >= unit1.LeftPosition && xPos <= (unit1.LeftPosition + 50) && yPos >= unit1.TopPosition && yPos <= (unit1.TopPosition + 50))) { collides = false; } } newMovingUnit.SetSteps(this.MinSpeed, this.MaxSpeed); _movingUnits.Add(newMovingUnit); } }
private void metroRadioGroup_MouseEnter(object sender, System.EventArgs e) { bMouse = MouseCapture.Inside; _tmrMouseLeave.Start(); Refresh(); }
private void UIListBoxItem_MouseEnter(object sender, EventArgs e) { _bMouse = MouseCapture.Inside; TmrMouseLeave.Start(); Refresh(); }
public void _MouseHoverIn() { m_MouseState = MouseCapture.Inside; tmrMouseLeave.Start(); }
public void _MouseHoverOut() { m_MouseState = MouseCapture.Outside; tmrMouseLeave.Stop(); }
private void This_MouseEnter(object sender, System.EventArgs e) { m_MouseState = MouseCapture.Inside; tmrMouseLeave.Start(); Refresh(); }