CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2003
    Posts
    124

    Load a form in Modal mode at Windows Stratup

    Hi all,

    I have a small program with just one form. I'll be placing this EXE in windows startup folder. What I would like to do is when Windows loads this form, I want to load this program and wait for the user to click ok. Its like how you open a form in showdialog mode but at startup.

    Thanks.

  2. #2
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    Re: Load a form in Modal mode at Windows Stratup

    Maybe add a sub Main to your program and set it as the startup, then in the sub main show the form as dialog? I think that should work.

  3. #3
    Join Date
    Apr 2003
    Posts
    124

    Re: Load a form in Modal mode at Windows Stratup

    Thanks for the reply. I do not know how to include the sub main and make it a dialog? Can you help me on that?

  4. #4
    Join Date
    Jun 2005
    Location
    Indianapolis
    Posts
    72

    Re: Load a form in Modal mode at Windows Stratup

    Add a module to your project (or modify your current one). You will need to set the subMain module to start first, rather than your form.


    Module subMain

    Public Sub Main()
    Dim fMain As "YOUR FORM NAME GOES HERE" = New Main
    fMain.ShowDialog()
    End Sub
    End Module

  5. #5
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Load a form in Modal mode at Windows Stratup

    Add a module to your project and put this code in it:

    Public Sub Main(Args() as string)
    Dim F as new Form1

    F.ShowDialog

    End


    Then in your projects properties, set the startup object to "Sub Main".

  6. #6
    Join Date
    Apr 2003
    Posts
    124

    Re: Load a form in Modal mode at Windows Stratup

    Thanks for the feedback. I tried both your options. When I run it from vb the form loads but I'm still able to click on other areas like the windows start button and the my form minimizes. Any ideas?

  7. #7
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Load a form in Modal mode at Windows Stratup

    The reason for this is that your form is shown modal, for your program and not modal for the system.
    I'd set the Form's TopMost Property to true.
    In design time you can set the TopMost property to True in the Properties Window.
    In code (Run time) you could do this :
    Code:
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.TopMost = True
    End Sub
    But still, You'll still be able to click the Start Button however

    I'd advise you to set your Form's FormBorderStyle property to None, casuing the form not to have a titlebar. And setting your form's WindowState property to Maximised.

    I do have something similar. I use it to prevent users from continuing without the right user name and password. It blocks the system keys such as Ctrl+Esc, Alt + Tab, and it reads the username from a text file.
    Only If the USername and Password corresponds with those in the textfile it allows you to go into Windows.
    There's another trick also. When this app is first run, there are no Textboxes or anything - just a black screen. To get the textboxes, you have to press a special key combination (easter egg). Once the secret key combination is pressed, the textboxes and login button are shown.
    I use this to prevent people from using my computer.

    Do you want it ¿
    Do you feel it will help you ¿
    Last edited by HanneSThEGreaT; September 9th, 2006 at 02:59 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured