Hey, I want to snap a rectangle onto a grid of 32x32 (on a picturebox)
The grid does draw and everything yes. But, I'm not sure how and I Googled and couldn't find a relevant answer. =/
Printable View
Hey, I want to snap a rectangle onto a grid of 32x32 (on a picturebox)
The grid does draw and everything yes. But, I'm not sure how and I Googled and couldn't find a relevant answer. =/
You need to get the position of the rect and the grid. Than you basically do this (but than in C#):
if (x > (grid_x-5) && x < (grid_x+5))
{
x = grid_x;
}
x -> left position of the rect
grid_x -> horizontal position of the grid line
5 -> distance of when the snapping should do its work
That are the basics, quite easy. But you need to make some more code for moving the rect when its snapped etc or when you still hold it etc etc...