user1175743
user1175743

Reputation:

How to get a control that is underneath another control?

I am trying to create a basic map editor for fun which consists of a scrollbox and paintbox (to draw the grid).

In the OnMouseDown event for the paintbox I create images at runtime and add them inside the scrollbox, the grid paintbox is painted above the images ( because if the grid was at the back it just would not look good ).

Here is a sample screen:

enter image description here

My question would solve two of my problems in one.

Here is where my problem lies, to solve the problems above I first need to get the Image under the mouse cursor. But because I paint my grid (paintbox) above the images, the cursor will only ever 'see' the paintbox grid, and not the underlying images.

I did experiment with copying the paintbox grid to a TImage but it came out all wrong and I was getting out of memory errors. The size of the maps could be quite large and so putting the grid onto a bitmap is not ideal due the memory and limitations etc.

The grid must go on the top, otherwise it would look something like this:

enter image description here

Which hides the grid, and I don't want that to happen.

So, how can I see past the paintbox and get to the images underneath, using FindVCLWindow or something similar?

Upvotes: 6

Views: 407

Answers (1)

NGLN
NGLN

Reputation: 43664

Set the Enabled property of the PaintBox to False. That will let the mouse messages go through.

Further:

In the OnMouseDown event for the PaintBox I create images at runtime and add them inside the scrollbox

Change that to the OnMouseDown event on the ScrollBox. Adjust the coordinates by ScrollBox.[Horz/Vert]Scrollbar.Position.

Upvotes: 8

Related Questions