Form call problem

kaveh rahimi 66 Reputation points
2021-05-20T12:41:55.273+00:00

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

Developer technologies | VB
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2021-05-20T14:44:54.347+00:00

    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
    

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.