mytab has a datagrid and when selections are made I need to change the contents of a label on the main form (lblInfo).
I have no problem getting the data to a variable but I can't find a way to access the labels properties to display my info from inside the code for mytab class.
How can I access this labels properties from the new class?
in vb6 I think it would have worked to write MainWindow.lblInfo = "whatever" but that doesn't work.
I tried initiating the main form as
public mainwin = new MainWindow
mainwin.show
then in the class go for mainwin.lblInfo
but this says mainwin is not declared. it may be inaccessible due to its protection level.
I feel like there is a concept I'm missing here. Any help appreciated. Thanks.
erwin hasanuddinPosted Aug 12, 2010, 11:47 AM
Why are you not try to create new property in your class with data type label, say the code like this:
Put this code in a class or add new class
=============================
Public Class Class1
Private mLabelInfo As Label
Public Property LabelInfo() As Label
Get
LabelInfo = mLabelInfo
End Get
Set(ByVal value As Label)
mLabelInfo = value
End Set
End Property
End Class
Put the code in a Form and add button named button1
=======================================
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim c1 As New Class1
c1.LabelInfo = Label1
c1.LabelInfo.Text = "Text Changed!"
End Sub
Try that and let me know the result