Forms

How to make a startup form Modal ?

when the form is in normal state, and then some other window is behind, if you click outside , the window disappears.
PaulrajAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Jeremy_DConnect With a Mentor Commented:
Making it modal isn't likely to happen. A modal form's definition is that the user has to perform some action on it before execution is given back to the calling code. Since your startup form has no calling code, it can't be modal. You can however start with a Sub Main and do a 'frmMain.Show vbModal' from there, but what you are probably looking for is a way to put your main window on top of all other windows. That can be done like this:

'-------------------------------------
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_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1

SetWindowPos frmMain.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
'-------------------------------------

Use HWND_NOTOPMOST in stead of HWND_TOPMOST to make it normal again.
0
 
GordonpCommented:
You get nothing for nothing I'm afraid.
But as i'm feeling generous...

you cant make the startup form modal, but there is a way to make the first form the user sees modal.

Gordon
0
 
GordonpCommented:
Since theres an answer for no  points I'll show you the easy way to do it.

Set Start up to Sub Main

then create sub main as

Sub Main()
    frmMain.Show vbModal
End Sub

Gordon
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
GordonpCommented:
Since theres an answer for no  points I'll show you the easy way to do it.

Set Start up to Sub Main

then create sub main as

Sub Main()
    frmMain.Show vbModal
End Sub

Gordon
0
 
GordonpCommented:
Oops!
0
 
Jeremy_DCommented:
Like I said...
0
All Courses

From novice to tech pro — start learning today.