I struggle to show a second form above the main form without losing focus.
I have tried ShowWindow(second.handle, SW_SHOWNOACTIVATE)
, but the mainform loses focus. If I set Visible := false
on the second window, the call to ShowWindow
does not activate the second form, but the windows is empty when shown...
Does anyone have a good recipe for this?
UPDATE: What I'm trying to do, is showing a notify-window at a given event. It's crucial that the main form does not lose focus at any time.
There has to be something wrong with your code.
I tested this code, it works:
procedure TForm1.Button1Click(Sender: TObject); begin ShowWindow(Form2.Handle, SW_SHOWNOACTIVATE); Form2.Visible := True; end;
Be careful to use Visible
, not Show
! Otherwise it'll override the SW_SHOWNOACTIVATE
.
You can show the window (non modal) and reset the focus to the mainwindow.
procedure TMainForm.ButtonClick(Sender: TObject); begin OtherForm.Show; SetFocus; end;
Tested on 2006.
This does not show the other form on top. But it is very counter intuitive to have a window on top that does not have the focus.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With