473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

setting a form property value from a class?

--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
3 1086
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: | last post by:
Hi, I am setting the NumericUpDown .Value property and the ValueChanged event is NOT being fired. Does this ONLY get fired when I change it on the UI and not programatically? Thanks
10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
7
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well....
3
by: Patrick | last post by:
I am dynamically creating TextArea and drop-down lists in ASP.NET using something like HtmlTextArea eachTextArea = new HtmlTextArea(); I tried to set the "name" of these TextAreas, etc. (e.g....
3
by: Marty McFly | last post by:
Hello, I have a control class that inherits from System.Web.UI.WebControls.Button. When I drag this control from the "My User Controls" tab in the toolbox onto the form, I want it to reflect the...
3
by: Mark Rae | last post by:
Hi, Just a general quickie on setting properties of user controls from the parent form. Let's say I have a user control called note.ascx which displays a datagrid. That datagrid is populated...
12
by: Rob | last post by:
Let's say you open Form1 that contains TabControl1 There are several tabs on TabControl1 Now you open a new Form2 that contains a User Control How can you determine the Selected tab in Form1...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.