Results 1 to 3 of 3

Thread: Load forms through Sub Main

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Posts
    4

    Load forms through Sub Main

    Hi,

    We have developed a Windows Application using vb.net. In this project, we have
    a public Module file and couple of Windows forms. we have a procedure named Main in the
    module file and we would like to load a form through this sub-routine. The code snippet
    is given below for your reference.

    Public Module Module1
    Public obj_frm_Test As New frmTest()

    Public Sub Main()
    obj_frm_Test.Show()
    End Sub
    End Module

    In frmTest, we have few windows controls to do the required processing. We set
    Sub Main as the startup objeect using project properties dialog box. Whn we execute
    our project now, frmTest comes to the foreground and it gets unloaded automatically by itself.
    Our understanding about this is, when Sub Main procedure goes out of scope, objects created
    inside this sub routine is destoryed automatically.

    Here, instead of Show(), when we use ShowDialog(), form stays in the foreground, we expect

    Show() function to behave in the similar way. The same piece of code when we execut it from

    Visual Basic 6.0, it works as we expect.

    Can you tell us what needs to be corrected in the above code, we look forward
    for your reply, thank you.

    Regards,
    Deva.

  2. #2
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651
    Deva

    You have to use the ShowDialog() method of the form if you want the form to remain in the foreground.

    VB Code:
    1. ' VB6
    2.  
    3. frmTest.Show vbModal
    4.  
    5. ' This is the VB.NET equivalent
    6. '
    7.  
    8. frmTest.ShowDialog()
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    The preferred way to load your first form from sub main would be

    Dim youform As New Form1
    Application.Run(yourform)

    This will run the form non modal I believe but will also keep your app running until you close that form.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

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