Recent

Author Topic: Moving Form out of visible screen area fails  (Read 1640 times)

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Moving Form out of visible screen area fails
« on: August 03, 2024, 05:09:11 am »
I have a form that I want to be created away from the visible screen area. The code does move the Form but only to the edge of the screen. It does not move it completely away from the visible area. How do I get it to be created out of the visible screen area, please? The attached screenshot shows where the form gets stuck. The code used is below:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.       Left := Screen.Width + 100;
  4. end;  
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

ASerge

  • Hero Member
  • *****
  • Posts: 2324
Re: Moving Form out of visible screen area fails
« Reply #1 on: August 03, 2024, 06:09:25 am »
I have a form that I want to be created away from the visible screen area. The code does move the Form but only to the edge of the screen. It does not move it completely away from the visible area.
Windows 7. Move it completely away from the visible area.

Jorg3000

  • Jr. Member
  • **
  • Posts: 70
Re: Moving Form out of visible screen area fails
« Reply #2 on: August 03, 2024, 06:25:10 am »
Hi!
After FormCreate the LCL must first evaluate the .Position value, e.g. poDesigned or poScreenCenter.
Therefore, the FormCreate event is too early to set .Left, because the LCL corrects the position afterwards.

Try setting the position in the OnShow event instead.
« Last Edit: August 03, 2024, 06:35:22 am by Jorg3000 »

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Re: Moving Form out of visible screen area fails
« Reply #3 on: August 03, 2024, 01:53:26 pm »
I have a form that I want to be created away from the visible screen area. The code does move the Form but only to the edge of the screen. It does not move it completely away from the visible area.
Windows 7. Move it completely away from the visible area.
Moving the form using the mouse away from the visible area works. I was trying to move it programmatically, and that only moves to visible screen area edges.
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Re: Moving Form out of visible screen area fails
« Reply #4 on: August 03, 2024, 01:54:50 pm »
Hi!
After FormCreate the LCL must first evaluate the .Position value, e.g. poDesigned or poScreenCenter.
Therefore, the FormCreate event is too early to set .Left, because the LCL corrects the position afterwards.

Try setting the position in the OnShow event instead.
Hi @Jorg3000 I tried setting the position in the OnShow event, same problem it sticks at the edge.
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

VisualLab

  • Sr. Member
  • ****
  • Posts: 499
Re: Moving Form out of visible screen area fails
« Reply #5 on: August 03, 2024, 04:42:01 pm »
I did a test. "It works for me!". I'm using:

- OS: Windows 10 64-bit,
- Lazarus: 3.4 64-bit.

The form is displayed as I wanted (as in the source code). As Jorg3000 wrote, you need to pay attention to the value of the Position property set for the displayed form. I'm attaching a very simple example.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs;
  9.  
  10. type
  11.   {TForm1}
  12.   TForm1 = class(TForm)
  13.     procedure FormCreate(Sender: TObject);
  14.     procedure FormShow(Sender: TObject);
  15.   public
  16.     IsPresent: Boolean;
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. {$R *.lfm}
  25.  
  26. {TForm1}
  27.  
  28. procedure TForm1.FormCreate(Sender: TObject);
  29. begin
  30.   IsPresent := False;
  31. end;
  32.  
  33. procedure TForm1.FormShow(Sender: TObject);
  34. begin
  35.   if not IsPresent
  36.    then
  37.     begin
  38.      IsPresent := True;
  39.      Left := Screen.Width - 100; // visible part of the form with its left edge
  40.     // Left := Screen.Width + 100; // form completely outside the visible area of the monitor (maybe visible on the second monitor)
  41.     end;
  42. end;
  43.  
  44. end.



EDIT: I noticed too late that it was about Linux (I didn't look at the upper edge of the attached screenshot). In addition, my computer sometimes uses a second monitor (TV). At the time of the test, it was turned off, but Windows "knows about it".
« Last Edit: August 03, 2024, 05:14:11 pm by VisualLab »

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Re: Moving Form out of visible screen area fails
« Reply #6 on: August 03, 2024, 06:15:10 pm »
EDIT: I noticed too late that it was about Linux (I didn't look at the upper edge of the attached screenshot). In addition, my computer sometimes uses a second monitor (TV). At the time of the test, it was turned off, but Windows "knows about it".
Please take a look at this
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Re: Moving Form out of visible screen area fails
« Reply #7 on: August 03, 2024, 06:17:16 pm »
I just noticed when I try to set the Forms Left position using the object inspector it allows me to do so as long as the number is a positive integer. When I type in -100 it instantly reverts to 0 ( zero ) Is this normal and expected behavior?
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Thaddy

  • Hero Member
  • *****
  • Posts: 15735
  • Censorship about opinions does not belong here.
Re: Moving Form out of visible screen area fails
« Reply #8 on: August 04, 2024, 07:43:35 am »
Yes this is normal behavior. If you want most of a form out of visible range do it on the right side ad or bottom.
« Last Edit: August 04, 2024, 08:03:59 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

VisualLab

  • Sr. Member
  • ****
  • Posts: 499
Re: Moving Form out of visible screen area fails
« Reply #9 on: August 04, 2024, 01:02:20 pm »
Yes this is normal behavior. If you want most of a form out of visible range do it on the right side ad or bottom.

But only in Linux? In Windows, Lazarus applications have no such limitations (I tested). For curiosity, I checked the behavior of programs created in Delphi and there are no limitations either (Delphi 12).

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Re: Moving Form out of visible screen area fails
« Reply #10 on: August 04, 2024, 03:38:29 pm »
Yes this is normal behavior. If you want most of a form out of visible range do it on the right side ad or bottom.
Thank you @Thaddy I am trying to debug and step into the code where it does this zeroing.
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Re: Moving Form out of visible screen area fails
« Reply #11 on: August 04, 2024, 03:44:53 pm »
But only in Linux?
What I have found so far in the code shows me the behavior will be consistent across all operating system platforms.

Hi @VisualLab steps to reproduce:

1. Project- -> New Project --> Application
2. Check Form1 left value in object inspector
3. Type in a negative value in the Object inspector Form1.Left property ( say -100 to test )
4. Press Enter and watch the value being reset to zero.

Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

tetrastes

  • Hero Member
  • *****
  • Posts: 540
Re: Moving Form out of visible screen area fails
« Reply #12 on: August 04, 2024, 09:20:12 pm »
4. Press Enter and watch the value being reset to zero.

At Windows it does not:

wp

  • Hero Member
  • *****
  • Posts: 12368
Re: Moving Form out of visible screen area fails
« Reply #13 on: August 04, 2024, 09:38:34 pm »
Also in Manjaro Linux with Laz main/fpc 3.2.2/gtk2 it does not. This is for undocked IDE. Is your IDE docked?

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Re: Moving Form out of visible screen area fails
« Reply #14 on: August 05, 2024, 01:36:58 am »
4. Press Enter and watch the value being reset to zero.

At Windows it does not:
This is interesting. The same code-base does different things depending on the OS? I am going to try and trace and debug this... Thank you very much for testing on windows.
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

 

TinyPortal © 2005-2018