Recent

Author Topic: SetBounds  (Read 4242 times)

RAW

  • Hero Member
  • *****
  • Posts: 868
SetBounds
« on: December 31, 2016, 01:01:36 pm »
Code: Pascal  [Select][+][-]
  1. Procedure TForm1.FormKeyDown(Sender: TObject; Var Key: Word;
  2.                              Shift: TShiftState);
  3.  Begin
  4.   // SCREEN WIDTH
  5.   If (Key = Ord('W')) And (ssShift In Shift)
  6.   Then SetBounds(0, Top, (Screen.WorkAreaWidth-14), Height);
  7.  
  8.   // STANDARD WIDTH
  9.   If (Key = Ord('W')) And (ssCtrl In Shift)
  10.   Then SetBounds((Screen.WorkAreaWidth -Self.Width)  Div 2,
  11.                  (Screen.WorkAreaHeight-Self.Height) Div 2,
  12.                   500, 500);
  13.  End;
  14.  

If I move the window to different positions on the screen and press "CTRL + W", then it appears in the middle of the screen as expected.
But if I use "SHIFT + W" first and after that "CTRL + W", then the window appears not in the middle of the screen.

The same if I maximize the window or if I dock the window to the left or right side of the screen and press "CTRL + W".
If I press "CTRL + W" a second time then it's working correct.

Obviously I miss something here ! ??? Why is it sometimes working and sometimes not?
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: SetBounds
« Reply #1 on: December 31, 2016, 02:06:15 pm »
Obviously I miss something here ! ??? Why is it sometimes working and sometimes not?
All right. After Shift+W form becomes the width of almost the whole work area, you set its position based on the width of the remaining part, i.e. slightly to the left, but set a new width, so it looks like not in the middle.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: SetBounds
« Reply #2 on: December 31, 2016, 05:52:09 pm »
@ASerge
Thanks a lot... stupid me! I can't believe this... :-[

Code: Pascal  [Select][+][-]
  1. Procedure TForm1.FormKeyDown(Sender: TObject; Var Key: Word;
  2.                              Shift: TShiftState);
  3.  Begin
  4.   // SCREEN WIDTH
  5.   If (Key = Ord('W')) And (ssShift In Shift)
  6.   Then SetBounds(0, Top, (Screen.WorkAreaWidth-14), Height);
  7.  
  8.   // STANDARD WIDTH
  9.   If (Key = Ord('W')) And (ssCtrl In Shift)
  10.   Then
  11.    Begin
  12.     If WindowState   = wsMaximized
  13.     Then WindowState:= wsNormal;
  14.  
  15.     SetBounds((Screen.WorkAreaWidth -500) Div 2,
  16.               (Screen.WorkAreaHeight-500) Div 2,
  17.                500, 500);
  18.    End;
  19.  End;
  20.  

The next computer I buy is a computer that is able to punch me on the back of my head every 2 hours. Maybe that helps in similar situations in the future. :D
I need a drink...
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

 

TinyPortal © 2005-2018