Referrencing controls on the main form from a class

E

EstroJen

Hey folks,

I'm trying to reference a control on a main form from a separate class.
For simplicity,
i'll show you a small example snippet. Everything compiles fine, but
nothing actually
happens on the main form.

Is it possible I have to declare and initialize the component in the
Cl_SP class?

Any help is greatly appreciated....Thanks.....Jen


Public Class Form1
#Region
..
lbl1 definition, initialization, etc...
..
#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim ss As New Cl_Sp
ss.tryit()
End Sub
End Class

Public Class Cl_Sp

Public sFrm As New Form1
Sub tryit()
sFrm.lbl1.Text = "Hey, Hey..."
End Sub
End Class
 
G

Guest

EstroJen,

The code in the class needs a reference to the form.

You could modify your class code like this:

Public Class Cl_Sp

Public sFrm As Form1

And then from the form's Load event:

Dim ss As New Cl_Sp

ss.sFrm = Me
ss.tryit()

Kerry Moorman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top