MouseDown on Label to close window

Xojo 2019r3.2, MacOS 11.4 Big Sur, Desktop Application

I have a window (wLogin) opened which has a label on it with a mousedown event which contains the following code:

Blockquote
Globals.iUserID = 0
Globals.sUserID = “ADMIN”
Globals.iAccessLevel = 2
wMain.ShowModal
wLogin.close
Return false
Blockquote

I have tested return both true and false with the same result. The problem is the wLogin window does not close and a TextField located on the same form executes the lostfocus event - which I do not want to happen. How can I make the wLogin window close and go away and the wMain window open.

The wMain window opens and loads Listboxes correctly but then a message box pops up from the wLogin window which says the UserID is invalid.

Background if it helps. I’m starting a new app that has a UserID and Access Level requirement. The wLogin is a pretty standard login that asks for UserID and Password and then compares them to stored values. I’m in the very early stages and want to skip having to enter a UserID and Password unless I am showing it to someone else who wants to see how it works. So I have a small label in a corner that has no significance to anything unless I click on it and then it just forces the login to the admin account. Just a short cut for testing.

Thanks for any help…

Can you put wLogin.close in wMain open event?
For the LostFocus event you will need to do a check and decide if the code will execute or not.

Try:

Globals.iUserID = 0
Globals.sUserID = “ADMIN”
Globals.iAccessLevel = 2
wMain.ShowModal
self.close
Return false

Michel has it (above)

If the window which is open was created using
dim L as new wLogin

then your line wLogin.close is most likely causing ANOTHER instance of wLogin to be created (implicit instantiation), and then closed.

With ShowModal, your code above waits for wMain to close before continuing. If you want to do it fluently, replace ShowModal by Show.

For the second issue, since wMain is showing, it’s expected any control in wLogin having the focus loses it (the whole window loses focus). You can’t prevent the event, as your TextField will always be activated once you show another window (and the event executes on purpose), but you can do tricks like this:
• Add a property to wLogin: ShouldDisregardFocusLosing as Boolean
• In your code above, add this: ShouldDisregardFocusLosing=true (before you show wMain, like at the first line).
• In the TextField’s LostFocus event add:
if ShouldDisregardFocusLosing then return 'Do not execute lines below if true.
//Your existing code here.

Thanks guys. Problem solved. On to new ones…

1 Like