Originally posted by AlvaroF1
You are right. This example is only to show what is not working.

Do you have other idea to control form's controls within a module?


Thanks.

In .net, there is no real need to use modules. They are only supported to help vb6 programmers, who are used to using them. Behind the scenes, .net creates a class which is globally imported throughout the project, and all of the properties, methods become shared.

What is actually wrong with your sample however, is that Form1 loads intially, end when you call Test(), you create another instance of Form1, which you never display.
Try the following and you will see what I mean:

VB Code:
  1. Module Module1
  2.     Public Sub Test()
  3.       Dim frm As New Form1
  4.       frm.Show()
  5.         If frm.Button2.Enabled = False Then
  6.             frm.Button2.Enabled = True
  7.         Else
  8.             frm.Button2.Enabled = False
  9.         End If
  10.     End Sub
  11. End Module


But why would you want to control a form's controls inside a module? I think you should encapsulate the code relating to a particular form whithin the form itself. If you had many forms with same functionality then this contolling the forms common controls within another class (or even a module if you like), but you would need to use the existing instance of each form to control it rather than creating a new instance.