Setting the text of a label from within a class

  • Thread starter Thread starter Nobody
  • Start date Start date
N

Nobody

This is something I'm purely looking to do while testing something out. I
have a label on a form and I want to set the text of this label from within
a class.

Thanks
 
The form where the label resides is its own class.

As long as you have a reference to your "form class" from within your
"custom class" you should not have any problems.

You can pass an instance in, or you can do something like this:
<Written in notepad>

Dim Openfrm As Form
For Each Openfrm In My.Application.OpenForms

If Openfrm Is My.Forms.TheFormINeed Then
Openfrm.Label1.text = "HelloWorld"
end if
Next

Miro
 
Nobody said:
This is something I'm purely looking to do while testing something out. I
have a label on a form and I want to set the text of this label from
within a class.

Thanks
I would be inclined to create a datasource from your class and bind the
label to one of its properties. A really nice "set and forget" way.
 
Hi,

As I understand your question well, then you want to make your called class
dependant from your caller.

That is something, you never would want to do.

If it is that important, then create inside the class a public variable that
you can use to put on your label by instance written in this message.

\\\
Dim myClass as new TheClass
myClass.Perform
mylabel = myClass.ThLabel
///

\\\
Public Class TheClass
public string the label = "Testing out seems to me Dunglish"
End Class
///

Cor
 
Thanks, I had figured that out yesterday and it will work for the testing
I'm doing. Once testing is done the form is going bye-bye so I won't need to
do this.
 
Thanks, I was trying something like that and it didn't work for me. I'll try
your code out and see how it goes.
 
Lets say your form is ( in your solutions explorer ) called frmMyForm

all you have to do is do something like this:
Dim Openfrm As Form
For Each Openfrm In My.Application.OpenForms
If Openfrm.name = frmMyForm.Name Then
Openfrm.Label1.text = "HelloWorld"
end if
Next

That way - if you change the "name" of the frmMyForm, then your intellisense
will pick it up.

Cheers'

Miro
 
Back
Top