By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

Snap to grid functionality???

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
"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

P: n/a
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.