Board index » delphi » Clicks outside a control...

Clicks outside a control...

I want to make sure that, whenever the user clicks outside a particular
control, the OnExit procedure for that control is called.
In particular, I want the OnExit procedure to be called when the user clicks
on any toolbar button or menu item and the control is active.
Is there any way to do this, or do I have to call the OnExit handler
manually from each button and menu item?
Thanks,

Simon

 

Re:Clicks outside a control...


Hi Simon,

procedure TForm1.OnExitForAll (Sender: TObject);
begin
If Sender is TLabel then with Sender as TLabel do begin ... end;
If Sender is TButton then with Sender as TButton do begin ... end;
If Sender is TEdit ..and so on...
end;

Rudy
===============================================
Simon McGregor schreef:

Quote
> I want to make sure that, whenever the user clicks outside a particular
> control, the OnExit procedure for that control is called.
> In particular, I want the OnExit procedure to be called when the user clicks
> on any toolbar button or menu item and the control is active.
> Is there any way to do this, or do I have to call the OnExit handler
> manually from each button and menu item?
> Thanks,

> Simon

Re:Clicks outside a control...


It seems to me you are describing exactly what an onExit-event does:
 provided that a control has focus, when the focus shift away ( f.i. someone
pusches a different button,
a form or whatever) it will go through the code you write in the onExit of this
particular control.
Maybe I'm not getting you right

bye, Bhas

Simon McGregor schreef:

Quote
> I want to make sure that, whenever the user clicks outside a particular
> control, the OnExit procedure for that control is called.
> In particular, I want the OnExit procedure to be called when the user clicks
> on any toolbar button or menu item and the control is active.
> Is there any way to do this, or do I have to call the OnExit handler
> manually from each button and menu item?
> Thanks,

> Simon

Re:Clicks outside a control...


Quote
>Hi Simon,

>procedure TForm1.OnExitForAll (Sender: TObject);
>begin
>If Sender is TLabel then with Sender as TLabel do begin ... end;
>If Sender is TButton then with Sender as TButton do begin ... end;
>If Sender is TEdit ..and so on...
>end;

>Rudy

Ah... Maybe I should have explained better.
I want my DrawGrid's OnExit handler to be called whenever it is active and a
user clicks outside it.
The problem is that clicking on a toolbar or menu button does not generate
an Exit message, because the DrawGrid does not become inactive.
I guess I could write a general OnClick handler for everything which first
calls DrawGridExit and then the specific handler for the component; is there
a better solution?

Thanks,

Simon :-)

Re:Clicks outside a control...


His problem is that the Toolbar button doesn't get the focus, so his
control doesn't lose the focus when the user clicks in one of those
buttons. (the SpeedButton or ToolbarButton they are not windowed
controls).

You can handle the WM_HITTEST messago to trap the mouse clicks and if it
was outside your control then you should trigger the OnExit for that
control (just check the ActiveControl property to do that...). I haven't
the time now to explain how to trap these messages, but surely someone
else could do it for you before I have the time...

Bye,
  Felipe Rocha Machado

Quote
Vic /Bhaskar Beffers wrote:

> It seems to me you are describing exactly what an onExit-event does:
>  provided that a control has focus, when the focus shift away ( f.i. someone
> pusches a different button,
> a form or whatever) it will go through the code you write in the onExit of this
> particular control.
> Maybe I'm not getting you right

> bye, Bhas

> Simon McGregor schreef:

> > I want to make sure that, whenever the user clicks outside a particular
> > control, the OnExit procedure for that control is called.
> > In particular, I want the OnExit procedure to be called when the user clicks
> > on any toolbar button or menu item and the control is active.
> > Is there any way to do this, or do I have to call the OnExit handler
> > manually from each button and menu item?
> > Thanks,

> > Simon

Re:Clicks outside a control...


Quote
> I want my DrawGrid's OnExit handler to be called whenever it is active and a
> user clicks outside it.
> The problem is that clicking on a toolbar or menu button does not generate
> an Exit message, because the DrawGrid does not become inactive.

If the OnEnter events are still available for all the other components, I
guess you could point them all to your OnExit.

I wonder if you could add a WM_MBHITTEST handler (I KNOW I've got that name
wrong) to each TMenuItem and TSpeedButton, and have it call your OnExit too?
I suppose you could create a descendant of each of these containing this
handler, and substitute them for the original components.

I'm not near my Delphi machine to check, but I suppose a control that doesn't
take the focus has neither OnEnter nor OnExit, so that puts the kibosh on
using OnEnter to call your routine.

Good luck,
Elliott

"I don't want to achieve immortality through my work. I want to achieve
it through not dying." -- Woody Allen

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

Other Threads