User right clicks square on gui to delete; Not working correctly c# -
my winforms program has bunch of boxes flying every way basic collision detector. user can add boxes wherever left click (so overlap quite often).
the issue: whenever user right-clicks square, squares within (based on center of other squares) one-square area supposed removed. sadly, seems work on top left of square. no right click in lower half, nor right half results in removal. on top of that, deletes farther , farther left should. code:
if (e.button == mousebuttons.right) { foreach (mysquare square in squarelist) { if (((mouseeventargs)e).x - (dimensions / 2) <= square.xposition & square.xposition <= ((mouseeventargs)e).x + (dimensions / 2)) { if (((mouseeventargs)e).y - (dimensions / 2) <= square.yposition & square.yposition <= ((mouseeventargs)e).y + (dimensions / 2)) { deletionlist.add(square); } } } foreach (mysquare square in deletionlist) { squarelist.remove(square); counter--; } }
where "dimensions" equal 20 (this can changed, initial value).
where have gone wrong?
edit: appclay, know based on top left corner, not center, which, frankly, makes quite bit of sense. in case in future cares, working code:
if (e.button == mousebuttons.right) { foreach (mysquare square in squarelist) { if (((square.xposition <= ((mouseeventargs)e).x & ((mouseeventargs)e).x - square.xposition <= dimensions))) { if (((mouseeventargs)e).y - dimensions <= square.yposition & square.yposition <= ((mouseeventargs)e).y) { deletionlist.add(square); } } } foreach (mysquare square in deletionlist) { squarelist.remove(square); counter--; } }
Comments
Post a Comment