c#/java Drag points and draw lines between them
Hey, is there a a simple way in c# or java to let the user "drop" points onto the form and then draw lines between the new point and existing ones ?
with simple way i mean a component/framework/whatever (or even already existend in c#/开发者_如何学Cjava ?)
Sure; it'll be framework and architecture dependent though. C# WPF will have a different way to do it then C# WinForms which will be different than Java Swing.
For Winforms, you'll simply create a Graphics object based on some area of your form bounded by a control (like a Panel or PictureBox), then on that Control's MouseClick event, log the mouse's current location and draw a line between that location and the location of the previous click (or all other clicks).
If you want to drag and drop, like from a toolbar, that's a little more complex; basically you need to track what you dragged and where you dropped it so when you drop it you can perform the proper action. I believe the arguments you'll get in the DragDrop handler will give you this information.
I am not aware of any lib that does that, but what I did to simplify things a bit is created usercontrol 2x2 which represented a point and allowed user to drop it onto form by drag and drop. Lines were drawn manually, however, in OnPaint(...)
精彩评论