current control


how do i found out which control i was currently on in the form??

i need to have a delete button to delete a stock record if the cursor is anywhere in the form, delete a document item if the cursor is in the document listbox or delete a offer item if the cursor is on the offer listbox.


You can use the property Window.Focus
If the result is Nil, it means there is no Focus.

The problem however is that as soon as you press the “Delete” button, the focus will be the Delete button and not the previous control.
The workaround is to use a Canvas with “AcceptFocus=False” or to use the MouseDown event of the Pushbutton.

[code] If self.Focus <> Nil then

MsgBox("The focus is on " + self.Focus.Name)

End If[/code]

if that is the case, is there a previous control function then??

Or what if i have variable that get set to something when i am in the listbox for offer and document and the same variable set to blank if the cursor is not there??

You could create a property in the Window to save the last focused item.

In your Listboxes and form controls GotFocus event, you can set the property to the name of the control.

But you will certainly have to set the property to be blank when the user clicks on another control to prevent deleting something the user didn’t want to.

i do exactly that… on got focus of the listbox , i set the variable to ‘FileLink’ and lost focus , set to “”. apply to offer listbox too… work beautifully now.

In this case, do you mean mouse cursor or the edit cursor? Also, do you want the user to be able to press the button with Enter/Return, or mouse click?

You could set a current control property for the window by using the MouseEnter/MouseExit events of those controls if you’re talking about the mouse cursor.

what ever i did above, it work on the Mac but not on the Window