[BUG] Form.SendToBack bring the Form to foreground !

Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #71304
    SzakiLaci
    Participant

    Very simply recreatable error:

    Make a 2th form
    put 2 buttons on the 1th : Show + Hide

    
    procedure TForm1.btn_hideClick(Sender: TObject);
    begin
        Form2.SendToBack;
    end;
    
    procedure TForm1.btn_ShowClick(Sender: TObject);
    begin
        Form2.Show;
    end;
    

    If you click Show, than Hide -> it brings the second form to Foreground, instead of sending it “back” ! 🙁

    Version: 17.01

    #71306
    chris2023
    Participant

    procedure TForm1.btn_ShowClick(Sender: TObject);
    begin
    Form2.Show;
    end;

    thats wrong it should to be
    procedure TForm1.btn_ShowClick(Sender: TObject);
    begin
    Form2.BringToFront;
    end;

    #71309
    SzakiLaci
    Participant

    Dear Chris,
    Thank you for trying to help, but you have misunderstood something very much.

    1. Nobody cares, how you bring that form2 to the front. (Mouse, Show, BringToFront, SetFocus )

    2. The problem is the opposite:
    – you can not send it behind the other form !
    Because even if it is already at the back, it brings it to front. What it SHOULD NOT !!!

    #71314
    SzakiLaci
    Participant

    This Solution WORKS fine:

    
    procedure Send_Form_to_Background(h: THandle);
    begin
        SetWindowPos(h, HWND_BOTTOM, 0,0, 0,0, SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSENDCHANGING or SWP_NOSIZE or SWP_NOOWNERZORDER);
    end;

    The “trick” is SWP_NOSENDCHANGING which prevents AC to interfere.
    link to MSDN SetWindowPos…

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.