interactive a coordinate system in a GUI
-
Hi guys,
i am trying to build up a GUI, in which there is a sub window with a x-y coordinate system. I will get the coordinate when i put my maus at any point within the sub window, more if I left-double-click one point within the sub window, then this point will be marked as a start point.
I hope i make myself clearly.
Any idea, how can I implement this in C#? Any kinds of material will be appreciated.
Regards,
bag
-
I will suggest you should use a simple canvas and catch the mouse down or double click event (I think there is one)
At this position you can create a ellipse at the mouse position, and I think it is a good idea to store the ellipse everywhere {o;Now you can connect the click event of the ellipse with a own function and react like you want
If the ellipse doesn't have a click event (I don't think so) you can check in the canvas click event if in the clicked area is an ellipse
You can set now the start point where you like, and mark it with another color or something like thatAt the end of the story you should have a list with points sorted by the X or Y coordinate and you can do what you want with them
//edit - replace rectangle by ellipse #gg
-
Hi Mr. Evil,
great. Thanks very much for your useful suggestion. The Canvas is totally new to me. I am reading some articles in the internet right now. I am exciting about this 'new' technology, at least for me
One more question, if I want the zoom effect, which means by rolling the mouse wheel the coordinate system can be either zoomed in or zoomed out. Is that also possible?
Regards,
bag
Mr Evil schrieb:
//edit - replace rectangle by ellipse #gg
-
Hi
I think this should not a problem
in the canvas the good thing is that you can work from the bottom left direction and position with the margin property
for me I think this should be possibleStore all ellipses in a list sort like you want
and create a method which shows the rectanglesFor example
show() { Delete all children in canvas for each ellipse in ellipseList Show ellipse with margin }
Now you react for e mouse wheel event {I think there is one} and on this in-/decrease a "zoom level" - this can be an integer, and in the "show" method, calculate with this "zoomlevel" the new margins and rectangle sizes, for example
elipse.margin = new Thikness(X * zoomlevel, Y * zoomlevel, 0, 0)
the easiest is if you store the ellipses as an own object which contains only the X and the Y coordinates, they you can use in the canvas as the margin, and paint the "point" from this point minus some pixels for the upper left position
show() { Delete all children in canvas for each ellipse in ellipseList { Margin = X * zoomlevel, Y * zoomlevel, 0, 0 // position by zoomlevel ElipseUpperLeft = (X - 5) * zoomlevel, (Y - 5) * zoomlevel // point size by zoomlevel Show Ellipse "ElipseUpperLeft" with "Margin" } }
// just an idea {o;
//edit
please keep in mind that "zoomlevel" should never be zero, because than all points will be paintet in the corner