473,414 Members | 1,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 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 4959
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Norm | last post by:
Does anyone know a fix to this problem? In the Windows Form Designer, I have set my snap-to grid setting to false. However, the controls on the form still snap to the grid. I have tried setting...
2
by: Rhonda | last post by:
Using AccessXP I have lost snap to grid on my system. New or existing databases do not snap to grid for forms and reports in design view. Anyone have an idea on how to get it back?? Thanks. ...
6
by: MLH | last post by:
You know, snap to grid when dragging a new command button or other object? If you used autocad (command line DOS) YOU know exactly what I mean. I want to size my objects - not be forced to snap...
1
by: Michel Racicot | last post by:
I know that this post don't really belong to this newsgroup, but I can't find any better... I'm currently using Microsoft Visual C# 2005 Express Edition Beta and I can't find the "snap to grid"...
1
by: Rob Richardson | last post by:
Greetings! I see from the group archives that a lot of people don't like how Snap to Grid works when placing controls on forms. I am now among that number. When I had the Windows Forms Designer...
1
by: Sam | last post by:
Hi guys I'm writing a small drawing program which has "snap to grid" mode and I want to display something (some kind of shapes for example a small square or circle which indicate the current...
1
by: Marc | last post by:
Hi, Anyone know how I can have my drag and drop form controls 'snap' to a grid like in windows desktop?
4
by: MangroveRoot | last post by:
A few years ago, I worked on a project in which I designed some tables, queries, forms, and reports. I'm reasonably certain that when I was designing the forms for that project, I set the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.