views:

135

answers:

2

I want to create a control (derived from TCustomControl) that is invisible but reacts to normal events (I want to use it to show a hint when moving the mouse over a custom element). I thought overriding the paint method and leaving it empty would do the job but unfortunately a rectangle is drawn where the component is.

How can I make the control completely invisible?

+7  A: 

You can inherit from TGraphicControl instead of from TCustomControl, and leave the paint handler empty. Nothing will be drawn.

If you need a windowed control, then you should make sure that it has no border and uses the parent background. See this question for info on how to do that. You may need to override CreateParams() as well, to remove the border style bits.

mghie
+1 as usual, great answer. Using TGraphicControl does it for me. Thanks!
Smasher
+1  A: 

If the control is not visible then process click messages in the parent, do a simple test for those being in the control's rectangle and use PostMessage to forward the message to the control. Such code may be more readable than empty paint handlers. Bri

Brian Frost
Ultimately, you've described exactly how `TGraphicControl` works. It has no window handle, so its parent detects relevant mouse and paint messages and forwards them.
Rob Kennedy