By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

setting a form property value from a class?

P: n/a
--button on the form
Private Sub btnClsTest_Click(...) Handles btnClsTest.Click
Dim a As New clsTest
End Sub

-------------------------------------------------------
'--property on my form
Public Property captionText() As String
Get

End Get
Set(ByVal Value As String)
Me.Text = Value
End Set
End Property
------------------------------------------------

Public Class clsTest
Public Sub New()
Dim frm As New Form1
frm.captionText = "test from clsTest"
End Sub
End Class

How can I make the text "test from clsTest" in the class constructor show
up in the caption bar of the form that instantiates this class?

Thanks,
Rich



Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

You need to pass a reference to the form to the class. In your
example you created a new form1 and changed the captiontext. The form was
never shown. Try something like this instead.

Public Class clsTest
Public Sub New(frm as form1)
frm.captionText = "test from clsTest"
End Sub
End Class
Ken
-------------------------
"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
--button on the form
Private Sub btnClsTest_Click(...) Handles btnClsTest.Click
Dim a As New clsTest
End Sub

-------------------------------------------------------
'--property on my form
Public Property captionText() As String
Get

End Get
Set(ByVal Value As String)
Me.Text = Value
End Set
End Property
------------------------------------------------

Public Class clsTest
Public Sub New()
Dim frm As New Form1
frm.captionText = "test from clsTest"
End Sub
End Class

How can I make the text "test from clsTest" in the class constructor show
up in the caption bar of the form that instantiates this class?

Thanks,
Rich




Nov 21 '05 #2

P: n/a
OK. That was the trick I was forgetting - to pass the form in as an
argument. Man, I wasn't thinking about "New" that is not the same instance
of the original form. Now it works correctly.

Thanks very much for your help.
Rich

"Ken Tucker [MVP]" wrote:
Hi,

You need to pass a reference to the form to the class. In your
example you created a new form1 and changed the captiontext. The form was
never shown. Try something like this instead.

Public Class clsTest
Public Sub New(frm as form1)
frm.captionText = "test from clsTest"
End Sub
End Class
Ken
-------------------------
"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
--button on the form
Private Sub btnClsTest_Click(...) Handles btnClsTest.Click
Dim a As New clsTest
End Sub

-------------------------------------------------------
'--property on my form
Public Property captionText() As String
Get

End Get
Set(ByVal Value As String)
Me.Text = Value
End Set
End Property
------------------------------------------------

Public Class clsTest
Public Sub New()
Dim frm As New Form1
frm.captionText = "test from clsTest"
End Sub
End Class

How can I make the text "test from clsTest" in the class constructor show
up in the caption bar of the form that instantiates this class?

Thanks,
Rich




Nov 21 '05 #3

P: n/a
In my not so humble opinion the proper way for dealing with these types of
situations is via event handlers. Declare an event in your class and have the
form be the consumer of the event. That way you can have the form determine
how it wants to react to whatever happened in your class, as opposed to the
class controlling the form's behavior.


Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.