[SOLVED] .Show() a TForm without stealing focus? lazarus / 31-LCL ---------------------------------------------------------------------- fatmonk · 2016-08-15 17:31 Is there a way to show a Form without the shown form taking focus? Note, I DO NOT want the parent form to take focus either. Thanks, -FM ---------------------------------------------------------------------- balazsszekely · 2016-08-15 18:05 You can try something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses LCLIntf, LCLType;...  Form2 := TForm2.Create(Application);  Form2.Show;  ShowWindow(Form2.Handle, SW_SHOWNOACTIVATE);...     PS: You did not specify the OS. The above code is tested under windows. ---------------------------------------------------------------------- fatmonk · 2016-08-15 20:26 The second form is automatically created when the application runs so I assume I don't need the Create() line. But SW_SHOWNOACTIVATE doesn't seem to make any difference, the form still takes focus by the look of things. (How is doing the  SW_SHOWNOACTIVATE after the Show() supposed to work? Does that not show and then deactivate the form?) -FM ---------------------------------------------------------------------- balazsszekely · 2016-08-16 04:33 Quote@fatmonk But SW_SHOWNOACTIVATE doesn't seem to make any difference, the form still takes focus by the look of things.Yes it does! Create a new application with two forms. Drop a TTimer to the main form, set interval to 5000. When the timer fires, show the second form with the following code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfMain.Timer1Timer(Sender: TObject);begin  Form2.Show;  ShowWindow(Form2.Handle, SW_SHOWNOACTIVATE);end; Before the second form shows you have 5 sec. to switch the focus to an external application. ---------------------------------------------------------------------- ASerge · 2016-08-16 08:34 Quote from: fatmonk on August 15, 2016, 07:31:26 pmIs there a way to show a Form without the shown form taking focus? Try Form.Visible := True instead of Form.Show ---------------------------------------------------------------------- fatmonk · 2016-08-17 10:36 @ASerge... Wow.. I had tried that but with the form initially set to invisible at the design stage and that gave me a SIGSEGV crash. However, leaving the form visible at design time but using visible.true instead of .show() seems to work - I don't know how, but it does. This now, however, highlights my next problem to solve in this little application - it turns out that my mouse underlay actually appears under the popup menus! (I couldn't see this problem before as showing the underlay was cancelling the popups). I'll return to my original thread on underlays to ask about hat particular problem. Thanks, FM ---------------------------------------------------------------------- fatmonk · 2016-08-17 11:57 Looking in customform.inc it seems that calling TForm.Show() actually does the following: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {---------- --------------------------------------------------------------------  procedure TCustomForm.Show;------------------------------------------- -----------------------------------}procedure TCustomForm.Show;begin  Visible := True;  BringToFront;end;  So it actually just sets Visible to true and then brings the form to the front (and takes focus, I assume). So just setting the form to visible achieves the same thing without bringing the form to the front. Perfect! -FM