call form from module vb.net

kaveh rahimi 66 Reputation points
2021-05-11T04:21:33.197+00:00

Hi ,I want call a form from module and after that the form executed return to module.How can I do that?
Please explain it by an example.
Thanks

Developer technologies | VB
{count} votes

1 answer

Sort by: Most helpful
  1. Peter Fleischer (former MVP) 19,341 Reputation points
    2021-05-11T04:37:42.297+00:00

    Hi,'try following console demo:

    Imports System.Windows.Forms
    
    Module Module1
    
      Sub Main()
        Try
          Dim c As New Demo
          c.Execute()
        Catch ex As Exception
          Console.WriteLine(ex.ToString)
        End Try
        Console.WriteLine("Continue enter key")
        Console.ReadKey()
    
      End Sub
    
      Friend Class Demo
    
        Friend Sub Execute()
          Application.EnableVisualStyles()
          Application.SetCompatibleTextRenderingDefault(False)
          Application.DoEvents()
          Application.Run(New Form1()) ' instantiate new Form and show it '
        End Sub
    
      End Class
    
      Friend Class Form1
        Inherits Form
    
        Private Label1 As New Label() With {.Text = "Form 1 loaded"}
        Public Sub New()
          AddHandler Me.Load, Sub()
                                Me.Controls.Add(Label1)
                              End Sub
        End Sub
    
      End Class
    
    End Module
    
    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.