question

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

Form call problem

Hi ,I call form1 in my module which is in console application.I receive "Type 'form1' is not defined" error.
I don't know how can I call form in module.
This is my code:
Imports System.Management
Imports System.Windows.Forms
Imports System.Runtime
Module module1
Public Class kh
Public Shared Sub dosomething()
Task.Run(Sub() updateform())
End Sub
Public Delegate Sub formdelegate()
Public Shared Sub updateform()
Dim f As form1 = Application.OpenForms("form1")
End Sub
Sub main()
'Dim f As New Form1
'Application.Run(Form1)
Console.WriteLine("ok")
End Sub
Please help
Thanks

dotnet-visual-basic
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.

1 Answer

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered XingyuZhao-MSFT commented

Try prepending the project's namespace in front of Form1. Also, you should check if OpenForms contains Form1 e.g.

 Dim form1  = Application.OpenForms("form1")
 If form1 IsNot Nothing
     CType(form1, Form1).Text = "Hello"
 End If
· 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.

I do so. but the error repeats for new name in the place of 'form1'

0 Votes 0 ·

Hi @kavehrahimi-5744 ,
You can share your project on OneDrive or GitHub, it will help others make a test.

0 Votes 0 ·