question

kavehrahimi-5744 avatar image
0 Votes"
kavehrahimi-5744 asked kavehrahimi-5744 commented

call form from module vb.net

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

dotnet-visual-basic
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


If the form and module are included into your application (i.e. you have a single project that contains the form and module), then did you consider the usual technique, like ‘Dim f As New Form1 : f.ShowDialog()’?


0 Votes 0 ·

Hi ,No thanks I didn't consider that.Please can you tell me what is f and why I have to use this statement?

0 Votes 0 ·

F is a variable that will help to work with your form. You can use another name. You do not have to use this statement, but if you want to show the form, you can use it.

0 Votes 0 ·

1 Answer

PeterFleischer-3316 avatar image
1 Vote"
PeterFleischer-3316 answered kavehrahimi-5744 commented

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

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Please can you say me here which form is called and why you had used try statement?
Thanks

0 Votes 0 ·

HI,
in console demo the Form1 class is instantiated and called.

try-catch I use because demo code is a part of more complex code where can be any error at run time.

0 Votes 0 ·