-
Drag dot over grid
Hi,
I'd like to create an application with has a grid.
On the grid is a dot which I want to be able to drag with my mouse (and later when the mouse thing works with a joystick).
In a lable on the side I whant to put value's (0-255) for the x and y axis.
Since I'm new to C# programming I don't have a clue on how to begin on it, I do have some experience with C++.
The question is, how do I get the dot on the grid(which is in a piicturebox) how do I move it and how can I project the value in the labels(the picturebox is net 255 pixel high or long..)
It should look like this: http://users.pandora.be/ymweb/grid2.jpg
Best regards,
Adam
-
My approach would be something like:
Create a panel on the form
Set the grid image as background image of the panel
create a graphics object out of the panel
on formload, draw a filled circle onto the panel using the graphics object acquired from the panel.
Store the x,y coordinates of the filledcircle somewhere, now have an event like onMouseDown of the panel where you will check wether the x,y coordinates of the mouse are inside the circle's radius, if so , redraw the circle according to the mouse x,y coordinates as long as the mouse btn is down.
Also let the circle only move the amount of pixels between each line of the grid , so it seems like its moving on the grid.
Also have a onMouseUp event. When that event happens, let the circle for what it is ...
That should work. I dont know wether there's a ready made solution built in C# for this, but this is how I would try and tackle this problem.
ps: are you from Belgium , if so then you are probably the third belgian member on this board :) .
-
hehe, yes I am from belgium.
Thanks for the post, I'll try to work it out.
More idea's are always welcome.
If somebody finds an example code... feel free ;)
-
How excactly do I draw a circle in the panel because i can't find many examples of graphic objects in panels.
-
Create a panel called output ...
then do
Code:
public partial class Form1 : Form {
private Graphics g;
private int xCo=10;
private int yCo=10;
private int width = 10;
public Form1() {
InitializeComponent();
this.g = this.output.CreateGraphics();
}
private void output_Paint(object sender, PaintEventArgs e) {
g.FillEllipse(new SolidBrush(Color.Black), this.xCo, this.yCo, this.width, this.width);
}
}
something like this....
btw: im from belgium too ( East-Flanders ... the groovy side of Belgium :D, unlike that peasant West-Flanders...)