Czy można ustawić gdzieś opcję, aby stworzony formularz -np. logowania- był widoczny zawsze na wierzchu?
Czy można ustawić gdzieś opcję, aby stworzony formularz -np. logowania- był widoczny zawsze na wierzchu?
Wstaw to w module:
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const HWND_TOPMOST = -1
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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 uFlags As Long) As Long
Public Sub AlwaysOnTop(caption As String)
Dim ret As Long
Dim hWnd As Long
hWnd = FindWindow(vbNullString, caption)
ret = SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Sub
A następnie w userfomie wywołaj AlwaysOnTop:
Private Sub UserForm_Initialize()
AlwaysOnTop Me.caption
End Sub.