0

I am currently making a Physics simulator, starting it off with vertical throwing. The simulator graphs the trail of the thrown object and then the user can move their cursor over the graph to see the speeds and coordinates of that specific point.

I've been trying to find a way to have a dot or a small circle of some sort (not a single pixel) on the graph to mark the point on the graph where the cursor is located. So for example if my cursor is at X=20, on the graph at (20, Y coordinate) I have a dot. The dot needs to move with the cursor. A good example is Google's function "grapher" (search for Y=2x+1 or any other function...).

The problems is that when moving the dot, the graph is erased as well, so I tried using a second transparent panel over the 1st one but that didn't work... Any ideas?

Thanks a lot!

cakelover
  • 166
  • 1
  • 8
  • What are you using: WPF or Winforms or what? AlsO: How do you create the graph? Which control, which events etc.. – TaW Jan 25 '15 at 16:49
  • I'm using Winforms. I create the graph using the Graphics package, drawing a line between every two consecutive points. I draw the graph on the normal Panel and the event is MouseMove (or something of sort). Again thank you and if you need any more information I'll happily give it! – cakelover Jan 25 '15 at 16:57
  • 1
    OK. This is the most comon error in Winforms GSI+ gaphics. You need to understand the basics first and there a gazillions of answers around here. Look for __'drawing persistent graphics'__! The key is to store the necessary data (maybe point and colors) in a persistent list at class level and to draw the real graphics in or from the `Paint` event using the `e.Graphics`. Your cursor 'circle' can be drawn in the movemove but the data __must be drawn from the Paint event__. To trigger it you call `Panel.Invalidate(),`..! - – TaW Jan 25 '15 at 17:01
  • BTW: Graphics is not a package. It is an helper object that does the drawing on a Bitmap it belongs to.. – TaW Jan 25 '15 at 17:04
  • You could also draw the path to a **Bitmap** and then display that in a PictureBox. Now wire up the MouseMove() and the Paint() event of the PictureBox and only draw the dot and update some Labels on the Form with the calculated values w/ respect to the current mouse position. – Idle_Mind Jan 25 '15 at 17:54
  • Yes, Idle is right. This is the other option for persistent graphics. [See here](http://stackoverflow.com/questions/27337825/picturebox-paintevent-with-other-method/27341797#27341797) for example code for both ways! – TaW Jan 25 '15 at 18:05

0 Answers0