Take a look on this tutorial on dragging the points with mouse.
If you are using a LineObj
instead of a curve, take a look on the FindNearestObject
method.
Also if you want to make some "area of sensitivity" for clicking, this method should help you to transform mouse coordinates in pixels to pane scale coordinates.
The main idea is to:
- subscribe for MouseDown
, MouseUp
and MouseMove
events
- in the handler for MouseDown
event check if clicked point is near the curve/graph object you want to move
- do the change in similar way that it is shown in example from the first link
EDIT
Regarding your edit:
Let's assume you have a horizontal curve myCurve
containing two points. Using FindNearestPoint
you can find nearest clicked point and the curve containing this point.
So you have:
// mousePt is where you clicked
CurveItem nearestCurve = null;
int nearestID = -1;
myPane.FindNearestPoint(mousePt, out nearestCurve, out nearestID);
if(nearestCurve!=null)
// remember the curve somewhere.
Next handle the MouseMove
and MouseUp
events to find out how much you need to move your curve. You need to know only the change in Y (or Y2) direction as the curve is horizontal and you probably do not want to move it along X axis.
When you'll find out how much you need to move your curve (dy
), just do:
for(int i=0; i<nearestCurve.Points.Count; i++)
nearestCurve.Points[i].Y += dy;
Regarding your second question, in the documentation for LineObj.Location.Y2
you have:
Note that the Y2 position is stored internally as a Height offset from Y.
And Width
/Height
properties can be set easily, so you can do it this way.