labels

G

Guest

i have 2 forms.. one is windows form and I have a lable there that i do want
to control from class1. I thought I could send a referense to the label but
I don't know how to do that in VB
How do I declare the referens in class2??? I need to change color+text from
class2


Public Class Clas1
Inherits System.Windows.Forms.UserControl
Friend WithEvents lblStatus As System.Windows.Forms.Label
private cl As new Class2

Cl = new Class2(lblStatus)
End class

Public Class Class2

Public Sub New(ByRef instLblText As System.Windows.Forms.Label)
Init()
End Sub

Private Sub Init()
'I need here to give instLblText a green background ans chande it's
color and update the grafic in clas one where the label is shown
End Sub
End class
 
A

Armin Zingler

Lamis said:
i have 2 forms.. one is windows form and I have a lable there that i
do want to control from class1. I thought I could send a referense
to the label but I don't know how to do that in VB
How do I declare the referens in class2??? I need to change
color+text from class2


Public Class Clas1
Inherits System.Windows.Forms.UserControl
Friend WithEvents lblStatus As System.Windows.Forms.Label
private cl As new Class2

Cl = new Class2(lblStatus)
End class

Public Class Class2

Public Sub New(ByRef instLblText As System.Windows.Forms.Label)

You don't have to pass it ByRef here. See also:
http://groups.google.com/group/microsoft.public.dotnet.languages.vb/msg/41e83beb9988aabf

Init()
End Sub

Private Sub Init()
'I need here to give instLblText a green background ans chande
it's color and update the grafic in clas one where the label is
shown
End Sub
End class


3 ways:

a) Change the color in Sub New - you already have the reference there:

instLblText.backcolor = color.green

b) Pass the reference to Sub Init:

Public Sub New(ByVal instLblText As System.Windows.Forms.Label)
Init(instLblText)
End Sub

Sub Init (Byval lbl As System.Windows.Forms.Label)

lbl.backcolor = color.green

end sub

c) Store the reference in a field - if you also need it later, not only in
sub New:

private f_Label as label

Public Sub New(ByVal instLblText As System.Windows.Forms.Label)
f_label = instLblText
Init()
End Sub

Sub Init ()

f_label.backcolor = color.green

end sub


Apart from this, I wonder why you want to pass the label at all. Isn't it
possible to do the same in Class1. I mean, that's (usually) what the
Usercontrol is used for.


Armin
 

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