Hello guys,
How to make Form2 always on top from Form1 BUT I can still click Command1(Command Button) at Form1.
Please help me.
Thanks.
Printable View
Hello guys,
How to make Form2 always on top from Form1 BUT I can still click Command1(Command Button) at Form1.
Please help me.
Thanks.
This must the most asked question on here, do a search.
VB Code:
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 Const SWP_NOMOVE = &H2 Const SWP_NOSIZE = &H1 Const SWP_SHOWWINDOW = &H40 Const SWP_NOACTIVATE = &H10 Const HWND_NOTOPMOST = -2 Const HWND_TOPMOST = -1 Private Sub FormOnTop(Handle As Integer, OnTop As Boolean) Dim wFlags As Long Dim PosFlag As Long wFlags = SWP_NOMOVE Or SWP_NOSIZE Or _ SWP_SHOWWINDOW Or SWP_NOACTIVATE Select Case OnTop Case True PosFlag = HWND_TOPMOST Case False PosFlag = HWND_NOTOPMOST End Select SetWindowPos Handle, PosFlag, 0, 0, 0, 0, wFlags End Sub Private Sub Form_Load() FormOnTop Me.hwnd, True End Sub Private Sub Form_Unload(Cancel As Integer) FormOnTop Me.hwnd, False End Sub
Keithuk,
I search about it but cannot find the suitable code. Anyway, thank you for your help.
:D
Keithuk's suggestion is the normal way of doing what you ask, but another way is to put this code in Form2.
VB Code:
Dim ctl As Control For Each ctl In Form1.Controls ctl.Enabled = False Next Form1.Command1.Enabled = True
Thanks Marty.
I assumed that he would put the code in Form2 because he wants Form2 on top.
Thou its wrong to assume. It makes an Ass out of U and Me, AssUMe.
Actually, I got my own solution already
VB Code:
'place this code in Form1 'Form2 will be on top of Form1 'Command Button (or others object) on Form1 still can be click Private Sub Command1_Click() Form2.Show , Form1 End Sub
Thanks again guys.