471,579 Members | 1,229 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,579 software developers and data experts.

Snap to grid functionality???

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
Nov 21 '05 #1
2 4819
"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
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
Nov 21 '05 #2
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
"Jeremy" <th***********@hotmail.com> wrote in message
news:8j******************@twister.tampabay.rr.com. ..
"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
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

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Norm | last post: by
2 posts views Thread by Rhonda | last post: by
1 post views Thread by Michel Racicot | last post: by
1 post views Thread by Rob Richardson | last post: by
1 post views Thread by Sam | last post: by
1 post views Thread by Marc | last post: by
4 posts views Thread by MangroveRoot | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Vinnie | last post: by
1 post views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.