I happened to have a simple example that as follows:
- The user can drag a line on the chart. The line will have two end points represented as two small rectangles.
- The user can drag the individual rectangles and hence change the line.
The original intention of the above is to provide a "ruler" or measurement interface on the chart. (The line is the ruler.) We wrote that for one of our customers and it is in C++/MFC. Our customer then modifies it to display the position, length and slope of the line segment somewhere in their user interface.
If the above is similar to what you need, I can port the code to VB on Windows Forms for you.
For your enquiry, it is correct that the "initDynamicLayer" will clear the dynamic layer.
In the sample code, you may notice there are already multiple circle points on the "track cursor". So to draw two fixed points, you just need to draw two fixed points after initDynamicLayer. Basically, your code needs to keep track of how many points you need to draw, and draw them.
As a simple example, your code can maintain the coordinates (x1, y1) and (x2, y2) for the position of the two points, and initialize them to (-999, -999) (or any invalid coordinates). In the code after initDynamicLayer, your code draws (x1, y1) and (x2, y2) only if they are valid coordinates.
When the user clicks on the plotarea, you may check if the mouse is on (x1, y1) or (x2, y2). If the mouse is not on either point and at least one of the points are invalid, then assign the mouse coordinates to the invalid point. This adds a point to the chart. If the mouse is clicked on a valid point, then assign invalid coordinates to that point. This removes the point. Then redraw the dynamic layer to update the display.
thank you for your help and the description in detail!
With the idea to maintain the coordinates (x1, y1) and (x2, y2) for the position of the two points, and initialize them to (-999, -999) it works really good!
My program set one point with a left click and the other one with the right click. So the program save the coordinates and draw the fixed points everytime it draws the moving point.