Snap to grid functionality???

S

SStory

I have a picture that I allow the user to move around and would like to
offer grid support like VB and other apps so that it will snap to the
nearest point.

How can I offer grid support so that the image will snap in place on
grid points like a commerical app? I am not sure how to implement that.

Anyone have any code?

Thanks,

Shane
 
J

Jeremy

SStory said:
I have a picture that I allow the user to move around and would like to
offer grid support like VB and other apps so that it will snap to the
nearest point.

How can I offer grid support so that the image will snap in place on
grid points like a commerical app? I am not sure how to implement that.

This is a very expansive question. Can you fully describe what you want?
For example, do you want it to snap to the grid when the mouse moves, when
they click, drag, drop, etc...

In VS.NET, the basic concept is this (drag and snap):

- When the user drags an object, the new object location is snapped to the
nearest grid point as the object moves.
- The grid spacing and snap distance are defined in the user settings
- Visual cues are rendered so the user knows what the grid looks like (and
thus, how the objects will snap to it).

- How does an object go into motion (Not using drag-n-drop)?
- Set flag when mouse goes down over object
- When mouse moves, check to see if the flag is set, if so, then we are
draging
- Set flag off when mouse goes up over object

- How does the snap work?
- starting from the origin, points are determined based on the grid size
- when an object moves, the closest point must be determined
- (y2 - y1) / (x2 - x1) = Distance (if I remember my Algebra
correctly)
- where XY1 is the current point, and XY2 are the 8 possible
neighbors
- the objects location is then set to the nearest point

- Use ControlPaint.DrawGrid( ) to draw the grid easily

Anyone have any code?

Nope, sorry.


HTH,
Jeremy
 
S

SStory

hmm..... interesting ideas...
yes I just have any number of pictures on a form in a picture box and the
user will click on one and drag it, although it won't be "drag and drop
there", just keeping track of the last mouse coord and making the adjustment
and redrawing.

When the user lets off the mousebutton I want it to snap.

Thanks for the input.... I will need to try the distance formula I guess and
make this work.
At least I have some idea now..

Shane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Snap Control to grid 1
freeform snap to grid 1
Snap to Grid 1
Snap to Grid - where did it go??? 3
More snap-to-grid wierdness 1
Snap to shape 4
drawing snap mode indicator 1
snap to grid 2

Top