private System.Drawing.Rectangle GetRectangle(PointHolder start, PointHolder end) { return(new System.Drawing.Rectangle((int)Math.Min(start.X, end.X), (int)Math.Min(start.Y, end.Y), (int)Math.Abs(start.X - end.X), (int)Math.Abs(start.Y - end.Y))); }
private void DisplayImage_MouseDown(object sender, MouseButtonEventArgs e) { if (!IsSelectingPoint) { foreach (var parkingArea in ParkingAreasCollection) { if (GetRectangle(parkingArea.StartingPoint, parkingArea.EndingPoint).Contains((int)e.GetPosition(DisplayImage).X, (int)e.GetPosition(DisplayImage).Y)) { HighlightParkingArea(parkingArea); SelectedParkingArea = parkingArea; return; } } return; } if (PointSelected) { ParkingAreasCollection.Add( new ParkingArea( SelectedPointStart, new PointHolder( e.GetPosition(DisplayImage).X, e.GetPosition(DisplayImage).Y))); IsSelectingPoint = false; DrawAreaOnBitmap(ParkingAreasCollection.Last()); } else { PointSelected = true; SelectedPointStart = new PointHolder(); SelectedPointStart.X = e.GetPosition(DisplayImage).X; SelectedPointStart.Y = e.GetPosition(DisplayImage).Y; } }
public ParkingArea(PointHolder p1, PointHolder p2) { StartingPoint = p1; EndingPoint = p2; }
private void Button_Click_2(object sender, RoutedEventArgs e) { SelectedPointStart = new PointHolder(); PointSelected = false; IsSelectingPoint = true; }