# Re: How to let form always on top in vb6

Posted by Someone on January 21, 1999 at 13:35:49:

In Reply to: How to let form always on top in vb6 posted by Fai on January 21, 1999 at 11:57:53:

Option Explicit
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 HWND_NOTOPMOST = -2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2

Public Sub SetOnTop(frm As Form, Topmost As Boolean)
If Topmost Then
SetWindowPos frm.hwnd, HWND_TOPMOST, 0, 0, 0, _
0, SWP_NOSIZE Or SWP_NOMOVE
Else
SetWindowPos frm.hwnd, HWND_NOTOPMOST, 0, 0, 0, _
0, SWP_NOSIZE Or SWP_NOMOVE
End If
End Sub
以上的程式码放在一个 Module 中

在 Form_Load 中输入：
SetOnTop Me, True

若非MDIForm直接在Show后面加 1 即可
Form.Show 1

Follow Ups: