Link to home
Start Free TrialLog in
Avatar of ADawn
ADawn

asked on

A form always (ON TOP)

I want to have a form always (ON TOP) and I don't want to use vbModal.
Avatar of Rubyn
Rubyn

Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1

Private Sub ShowWindowTopMost(Obj As Form)
    Call SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 100, 100, SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE)
End Sub

Private Sub Form_Load()
    Call ShowWindowTopMost(Me)
End Sub

You can also show any form using this function without using form1.show else you can use on form which is already shown to make it top most

This is exactly what you asked. :)
ASKER CERTIFIED SOLUTION
Avatar of Fuisseran
Fuisseran

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Richie_Simonetti
For that code to works, you should full test it with a compiled version of your program.
Cheers
try
YourForm.Show vbModeless, MainForm

The API suggestion above will put the form in top of ALL applications, vbModeless only in from of the form MainForm

Cheers
Hi ADawn,
This old question (QID 20558662) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

-->Accept Fuisseran 's comments as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

GPrentice00
EE Cleanup Volunteer