none
form.show() close immediately RRS feed

  • Question

  • I am a beginner of vb.net. I know someone asked this question before. But the answer does not work at all. Here is my code:

          

    Sub main()
            Dim Form1 As New frmEntry

            Form1.Show()

    End Sub

    The form disappears immediately after it appears.

    Monday, February 10, 2020 3:21 AM

All replies

  • Hello,

    Instead of Form1.Show() use Form1.ShowDialog(). Also unless there is a good reason you should start the main form as in a default project. If there is something that needs to be done prior to the form being shown there are other ways to do so but need more information to why you are using Sub Main rather than how a form is shown by default.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, February 10, 2020 3:40 AM
    Moderator
  • Hi,

    What is "frmEntry"?

    Regards,

    Ashidacchi -- http://hokusosha.com

    Monday, February 10, 2020 4:20 AM
  • I am a beginner of vb.net. I know someone asked this question before. But the answer does not work at all. Here is my code:

          

    Sub main()
            Dim Form1 As New frmEntry

            Form1.Show()

    End Sub

    The form disappears immediately after it appears.

    This is a VB Console App from which you're attempting to show Windows Forms.  You don't have an application message pump/loop to keep the app alive.  The VB Console App (Sub main()) is doing exactly what it's supposed to do - it executes each line in its block once and then exits immediately.

    If you want a WinForms Application, make a WinForms Application.

    Monday, February 10, 2020 5:43 AM
  • Hi antidinosaur,

    Thank you for posting here.

    As Andrew B. Painter suggested, you need to create form in windows form application.

    Follow the steps in following document to create a windows form application.

    Create a Windows Forms app in Visual Studio with Visual Basic

    Hope it could be helpful.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 10, 2020 6:43 AM
    Moderator
  • Hi antidinosaur,

    Did you solve your problem? If your question has been answered then please click the "Mark as Answer" Link at the bottom of the correct post(s), so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 26, 2020 2:05 AM
    Moderator