I'm working on a floor planner tool. More or less a program for scraping blueprints together with customization available.
Say I figure out how to import the furniture into the program. How do I go about making objects draggable on the form?
I'm working on a floor planner tool. More or less a program for scraping blueprints together with customization available.
Say I figure out how to import the furniture into the program. How do I go about making objects draggable on the form?
One way of doing it would be to add your objects and change their location based on the mouse's coordinates while moving. Doing some more adjustments and centering the location movement would make the change in location smoother. Here's an example (in C#):
For example, you have a class for an object.
public class Object {
string _name;
int sizeX;
int sizeY;
int locationX;
int locationY;
public Object(string name) {
locationX = 0;
locationY = 0;
switch(name) {
case "chair":
_name = name;
sizeX = 50; //Predefined width of the chair object
sizeY = 70; //Predefined height of the chair object
case ... //Continue with the process
}
}
public void setLocation(int x, int y) {
locationX = x;
locationY = y;
}
}
So, now you could go into the main form.
public void moveObject() {
Point coordinates = GetMouseCoordinates(); //There are a lot of ways.
chair.setLocation(coordinates.X, coordinates.Y);
}
For even smoother movement do this:
public void moveObject() {
MouseCoordinates coordinates = GetMouseCoordinates(); //There are a lot of ways.
chair.locationY = coordinates.Y + chair.sizeY / 2;
chair.locationX = coordinates.X + chair.sizeX / 2;
}
This is literally the simplest way. There are a ton of ways to make draggable objects on WinForm. However, if you want to make something like AutoCAD, 2D Animators etc. you will need to create a coordinate/grid system, which is really easy. You just need to create classes and use the concept of Object Oriented Programming(OOP).