How to make my non-modal forms to always be on top of my main form?
I have tried:
procedure TForm3.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.WndParent := Application.MainForm.Handle;
end;
Which seems to work fine. Is that correct way?
You can bring a Form on top of application by simply setting the Form. topmost form property to true will force the form to the top layer of the screen, while leaving the user able to enter data in the forms below. Topmost forms are always displayed at the highest point in the z-order of the windows on the desktop.
And in VB.NET, it is simple to keep a form at the top using the TopMost property of the form as True. After setting the TopMost property to true, the Uppermost form of a Windows application that overlaps all other forms, even if the Uppermost form is not in the active or foreground form.
Where did the name of the application appear in VB net? At the top of the form there is a title bar which displays the forms title. Form1 is the default name, you can change the name to your convenience . The title bar also includes the control box, which holds the minimize, maximize, and close buttons.
This is the Win32 concept of window ownership. An owned window always appears on top of its owner. The owner is specified in the call to CreateWindow and can then not be modified.
In the VCL you specify the owner by setting WndParent in CreateParams, and the framework then passes that on to CreateWindow. The VCL does this for you but in older versions the owner handling is, well, somewhat flaky. Modern versions are better and allow more control through the PopupMode and PopupParent properties.
Your code will therefore have the effect that you desire.
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