Re: How to drag graphic elements
- Posted by Derek Parnell <ddparnell at bigpond.com> Feb 13, 2007
- 481 views
Joel Garcia wrote: > > I'm looking for any advice on how to go about accomplishing the following: > > I wish to display two points in a window and draw a line between them. Then > I would like to be able to drag either of the points around the window while > maintaining the line between them. If necessary, the points could be > represented > by a bitmap, icon, control or whatever works, though I wish to keep the object > small (perhaps 10x10 pixels). Any help is appreciated. > > I am currently using the Win32Lib, but am open to other resources. Easy enough. Firstly, use a Pixmap as the drawing surface and during the onPaint event bitblt the pixmap to the Window. After drawing the initial points and the line, watch for mouse button down events on the window. If one occurs near or on a point, then watch for mouse movements events until the mouse button up event happens. During the movement events, clear the pixmap and redraw the points at the new location determined by where the mouse currently is, and redraw the line between them. That's basically it. -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell