Recent

Author Topic: Completely remove the focus from a form  (Read 3566 times)

simone

  • Sr. Member
  • ****
  • Posts: 419
Completely remove the focus from a form
« on: December 03, 2021, 12:37:56 am »
Is it possible to completely remove the focus from a form? In other words, I want a form without any controls with the active focus. I found this old issue:

https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/25396

which reports that TForm.ActiveControl: = nil is not working. It seems to me that the problem has not been solved. Do you have any suggestions? Thanks.
Microsoft Windows 10 64 bit - Lazarus 2.0.12

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1793
  • Former Delphi 1-7, 10.2 user
Re: Completely remove the focus from a form
« Reply #1 on: December 03, 2021, 12:51:10 am »
I want a form without any controls with the active focus.

Set the tabstop property of the controls to false. Works for me.
Lazarus 2.3, FPC 3.3.1 macOS 12.1 x86_64 Xcode 13.2
Lazarus 2.3, FPC 3.3.1 macOS 12.1 aarch64 Xcode 13.2
Lazarus 2.3, FPC 3.2.2 FreeBSD 13.0 amd64 VM
Lazarus 2.3, FPC 3.2.2 FreeBSD 12.2 amd64 VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 VM
Lazarus 2.0.10 FPC 3.2.0 Win10 amd64 VM

simone

  • Sr. Member
  • ****
  • Posts: 419
Re: Completely remove the focus from a form
« Reply #2 on: December 03, 2021, 03:36:01 pm »
Thanks Trev, your solution works. The only drawback, if I understand correctly, is that I have to set TabStop to False in every control that can receive the focus. I tried under Windows. Do you know if it also works with other widgets?
Microsoft Windows 10 64 bit - Lazarus 2.0.12

jamie

  • Hero Member
  • *****
  • Posts: 5129
Re: Completely remove the focus from a form
« Reply #3 on: December 03, 2021, 05:04:00 pm »
What does the "Disable" property do for you ?
I assume the form does have one.
The only true wisdom is knowing you know nothing

simone

  • Sr. Member
  • ****
  • Posts: 419
Re: Completely remove the focus from a form
« Reply #4 on: December 03, 2021, 05:26:11 pm »
I did not understand your answer. Which 'disable' property are you referring to?
Microsoft Windows 10 64 bit - Lazarus 2.0.12

jamie

  • Hero Member
  • *****
  • Posts: 5129
Re: Completely remove the focus from a form
« Reply #5 on: December 03, 2021, 05:28:12 pm »
The form has a "Enabled" property, that disallows input.
The only true wisdom is knowing you know nothing

simone

  • Sr. Member
  • ****
  • Posts: 419
Re: Completely remove the focus from a form
« Reply #6 on: December 03, 2021, 05:52:11 pm »
You wrote 'disable', not 'enabled'. For this I did not understand.  Thank you for your suggestion.  I can't prove it now.  But in this way I disable mouse and key input for the form and the controls inside it?
Microsoft Windows 10 64 bit - Lazarus 2.0.12

jamie

  • Hero Member
  • *****
  • Posts: 5129
Re: Completely remove the focus from a form
« Reply #7 on: December 03, 2021, 07:12:16 pm »
Yup
The only true wisdom is knowing you know nothing

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1793
  • Former Delphi 1-7, 10.2 user
Re: Completely remove the focus from a form
« Reply #8 on: December 03, 2021, 09:10:39 pm »
Thanks Trev, your solution works. [...]I tried under Windows. Do you know if it also works with other widgets?

Works for me in Cocoa and GTK2.
Lazarus 2.3, FPC 3.3.1 macOS 12.1 x86_64 Xcode 13.2
Lazarus 2.3, FPC 3.3.1 macOS 12.1 aarch64 Xcode 13.2
Lazarus 2.3, FPC 3.2.2 FreeBSD 13.0 amd64 VM
Lazarus 2.3, FPC 3.2.2 FreeBSD 12.2 amd64 VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 VM
Lazarus 2.0.10 FPC 3.2.0 Win10 amd64 VM

 

TinyPortal © 2005-2018