views:

352

answers:

3

I need to develop an application in Delphi where i have a TDrawGrid control and an image is displayed in the cells of the grid depending upon the kind of layout i select. i draw a line on the canvas of a the cell. the functionality i need to provide is drawing a line, drawing multiple lines on a imgae iside the cell, select any one line and move it, expand it, delete it.

Is there any way to make the lines as controls at runtime so that they all respond to mouse events.

+1  A: 

You can create custom controls. (Be sure to have a look at the component writers manual because there are some catches).

You can start looking at the TShape control. It is used for simple shapes. Maybe you can expand on it to support lines.

Gamecat
+2  A: 

I would advise against implementing your drawing objects as non-windowed VCL controls. You will not gain much from that, but some things (like hit-testing) would be much more difficult than when coding this on your own.

VCL controls are rectangular, so for parallel diagonal lines one control would be on top of the other, at least partially. Generally mouse events reach only the topmost control in the Z-order. That's something you would have to correct in your own code.

Selected lines should have the end points marked, so the user knows where to grab them for moving or resizing. Again, something a custom control does not provide (at runtime), so you'd have to code this.

I would probably simply create a line object class, and implement all functionality for creation, drawing, selecting, moving and resizing, deleting lines myself.

mghie
A: 

In the past I've created a network design application that used shapes, text, & connecting lines. I utilised DevExpress' ExpressFlowChart product which, whilst it has a few foibles, made the task relatively straightforward.

As mghie mentioned, hit-testing is one particularly problematic pain-point. It's nice to have someone do some of that heavy lifting for you.

moobaa