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

Accesing form controls from another class than the one tha created them

P: n/a
Hi,

I have a form with some controls, and a different class that needs to
modify some control properties at run time.

Hoy can I reference the from so I have access to its controls and
therefore being able to modify its properties?

Regards,

Mike


Oct 25 '07 #1
Share this Question
Share on Google+
16 Replies


P: n/a
"Mike" <mi**@hitnext.comschrieb
Hi,

I have a form with some controls, and a different class that needs
to modify some control properties at run time.

Hoy can I reference the from so I have access to its controls and
therefore being able to modify its properties?
Pass the Form reference to the class.
Armin
Oct 25 '07 #2

P: n/a
On Oct 25, 11:34 am, "Mike" <m...@hitnext.comwrote:
Hi,

I have a form with some controls, and a different class that needs to
modify some control properties at run time.

Hoy can I reference the from so I have access to its controls and
therefore being able to modify its properties?

Regards,

Mike
My personal preference is to keep the Controls private, and only
expose the necessary functionality via properties. This prevents an
outside object from being able to modify more than you want to have
modified.

For example, if you want a second form to be able to modify a label's
text property expose it like this:

////////////
Public Property MyLabelText() As String
Get
Return MyLabel.Text
End Get
Set (ByVal value As String)
MyLabel.Text = value
End Get
End Property
///////////

If instead you gave them a complete reference to the label, nothing
would stop them from calling form.MyLabel.Dispose() or something else
you didn't intend. In other words, using a property maintains
encapsulation.

Thanks,

Seth Rowe

Oct 25 '07 #3

P: n/a
Ok, I did, buy from the 2nd form, how do I reference the forms'
property?

Is it a direct call, like:

frmMain.Myproperty = MyValue

or

Dim frm As new frmMain
With frmMain
.MyProperty = MyValue
End With

I have tried both an none of them seem to work.

Thanks!
-----Original Message-----
From: rowe_newsgroups [mailto:ro********@yahoo.com]
Posted At: Thursday, October 25, 2007 2:01 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one tha
created them
Subject: Re: Accesing form controls from another class than the one tha
created them

On Oct 25, 11:34 am, "Mike" <m...@hitnext.comwrote:
Hi,

I have a form with some controls, and a different class that needs to
modify some control properties at run time.

Hoy can I reference the from so I have access to its controls and
therefore being able to modify its properties?

Regards,

Mike
My personal preference is to keep the Controls private, and only
expose the necessary functionality via properties. This prevents an
outside object from being able to modify more than you want to have
modified.

For example, if you want a second form to be able to modify a label's
text property expose it like this:

////////////
Public Property MyLabelText() As String
Get
Return MyLabel.Text
End Get
Set (ByVal value As String)
MyLabel.Text = value
End Get
End Property
///////////

If instead you gave them a complete reference to the label, nothing
would stop them from calling form.MyLabel.Dispose() or something else
you didn't intend. In other words, using a property maintains
encapsulation.

Thanks,

Seth Rowe

Oct 25 '07 #4

P: n/a
It is the first, where frmMain is a reference to the existing first
form that you somehow passed into the second form.

The second piece of code creates a new instance of your form, not
something that you want to do.

By the way, saying "none of them seem to work" without giving any
details is not very useful. Error message? No error but had no
effect? Had an effect you did not want?

What does the property definition in form1 look like?

On Thu, 25 Oct 2007 14:43:54 -0400, "Mike" <mi**@hitnext.comwrote:
>Ok, I did, buy from the 2nd form, how do I reference the forms'
property?

Is it a direct call, like:

frmMain.Myproperty = MyValue

or

Dim frm As new frmMain
With frmMain
.MyProperty = MyValue
End With

I have tried both an none of them seem to work.

Thanks!
-----Original Message-----
From: rowe_newsgroups [mailto:ro********@yahoo.com]
Posted At: Thursday, October 25, 2007 2:01 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one tha
created them
Subject: Re: Accesing form controls from another class than the one tha
created them

On Oct 25, 11:34 am, "Mike" <m...@hitnext.comwrote:
>Hi,

I have a form with some controls, and a different class that needs to
modify some control properties at run time.

Hoy can I reference the from so I have access to its controls and
therefore being able to modify its properties?

Regards,

Mike

My personal preference is to keep the Controls private, and only
expose the necessary functionality via properties. This prevents an
outside object from being able to modify more than you want to have
modified.

For example, if you want a second form to be able to modify a label's
text property expose it like this:

////////////
Public Property MyLabelText() As String
Get
Return MyLabel.Text
End Get
Set (ByVal value As String)
MyLabel.Text = value
End Get
End Property
///////////

If instead you gave them a complete reference to the label, nothing
would stop them from calling form.MyLabel.Dispose() or something else
you didn't intend. In other words, using a property maintains
encapsulation.

Thanks,

Seth Rowe
Oct 26 '07 #5

P: n/a


This is the property definition:

Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN.Text = value
End Set
End Property
And from the other form I call frmMain.TextboxWTN = "Whatever"
It has no effect over the form's textbox.

Thanks

-----Original Message-----
From: Jack Jackson [mailto:ja********@pebbleridge.com]
Posted At: Thursday, October 25, 2007 9:52 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one tha
created them
Subject: Re: Accesing form controls from another class than the one tha
created them

It is the first, where frmMain is a reference to the existing first
form that you somehow passed into the second form.

The second piece of code creates a new instance of your form, not
something that you want to do.

By the way, saying "none of them seem to work" without giving any
details is not very useful. Error message? No error but had no
effect? Had an effect you did not want?

What does the property definition in form1 look like?

On Thu, 25 Oct 2007 14:43:54 -0400, "Mike" <mi**@hitnext.comwrote:
>Ok, I did, buy from the 2nd form, how do I reference the forms'
property?

Is it a direct call, like:

frmMain.Myproperty = MyValue

or

Dim frm As new frmMain
With frmMain
.MyProperty = MyValue
End With

I have tried both an none of them seem to work.

Thanks!
-----Original Message-----
From: rowe_newsgroups [mailto:ro********@yahoo.com]
Posted At: Thursday, October 25, 2007 2:01 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
>created them
Subject: Re: Accesing form controls from another class than the one tha
created them

On Oct 25, 11:34 am, "Mike" <m...@hitnext.comwrote:
>Hi,

I have a form with some controls, and a different class that needs to
modify some control properties at run time.

Hoy can I reference the from so I have access to its controls and
therefore being able to modify its properties?

Regards,

Mike

My personal preference is to keep the Controls private, and only
expose the necessary functionality via properties. This prevents an
outside object from being able to modify more than you want to have
modified.

For example, if you want a second form to be able to modify a label's
text property expose it like this:

////////////
Public Property MyLabelText() As String
Get
Return MyLabel.Text
End Get
Set (ByVal value As String)
MyLabel.Text = value
End Get
End Property
///////////

If instead you gave them a complete reference to the label, nothing
would stop them from calling form.MyLabel.Dispose() or something else
you didn't intend. In other words, using a property maintains
encapsulation.

Thanks,

Seth Rowe
Oct 26 '07 #6

P: n/a
On Oct 25, 11:06 pm, "Mike" <m...@hitnext.comwrote:
This is the property definition:

Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN.Text = value
End Set
End Property

And from the other form I call frmMain.TextboxWTN = "Whatever"

It has no effect over the form's textbox.

Thanks

-----Original Message-----
From: Jack Jackson [mailto:jacknos...@pebbleridge.com]

Posted At: Thursday, October 25, 2007 9:52 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one tha
created them
Subject: Re: Accesing form controls from another class than the one tha
created them

It is the first, where frmMain is a reference to the existing first
form that you somehow passed into the second form.

The second piece of code creates a new instance of your form, not
something that you want to do.

By the way, saying "none of them seem to work" without giving any
details is not very useful. Error message? No error but had no
effect? Had an effect you did not want?

What does the property definition in form1 look like?

On Thu, 25 Oct 2007 14:43:54 -0400, "Mike" <m...@hitnext.comwrote:
Ok, I did, buy from the 2nd form, how do I reference the forms'
property?
Is it a direct call, like:
frmMain.Myproperty = MyValue
or
Dim frm As new frmMain
With frmMain
.MyProperty = MyValue
End With
I have tried both an none of them seem to work.
Thanks!
-----Original Message-----
From: rowe_newsgroups [mailto:rowe_em...@yahoo.com]
Posted At: Thursday, October 25, 2007 2:01 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
created them
Subject: Re: Accesing form controls from another class than the one tha
created them
On Oct 25, 11:34 am, "Mike" <m...@hitnext.comwrote:
Hi,
I have a form with some controls, and a different class that needs to
modify some control properties at run time.
Hoy can I reference the from so I have access to its controls and
therefore being able to modify its properties?
Regards,
Mike
My personal preference is to keep the Controls private, and only
expose the necessary functionality via properties. This prevents an
outside object from being able to modify more than you want to have
modified.
For example, if you want a second form to be able to modify a label's
text property expose it like this:
////////////
Public Property MyLabelText() As String
Get
Return MyLabel.Text
End Get
Set (ByVal value As String)
MyLabel.Text = value
End Get
End Property
///////////
If instead you gave them a complete reference to the label, nothing
would stop them from calling form.MyLabel.Dispose() or something else
you didn't intend. In other words, using a property maintains
encapsulation.
Thanks,
Seth Rowe
Are you sure you have a reference to the other form? If you
instantiate an new "frmMain" like you did in a previous example, you
will not be accomplishing anything. Perhaps you could post the code
where you are retrieving the reference to frmMain?

Thanks,

Seth Rowe

Oct 26 '07 #7

P: n/a

Form 1 (frmCall)

Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN.Text = value
End Set
End Property
Form 2

frmCall.TextboxWTN = "Something"
This is all I have

Thanks

-----Original Message-----
From: rowe_newsgroups [mailto:ro********@yahoo.com]
Posted At: Friday, October 26, 2007 6:36 AM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one tha
created them
Subject: Re: Accesing form controls from another class than the one tha
created them

On Oct 25, 11:06 pm, "Mike" <m...@hitnext.comwrote:
This is the property definition:

Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN.Text = value
End Set
End Property

And from the other form I call frmMain.TextboxWTN = "Whatever"

It has no effect over the form's textbox.

Thanks

-----Original Message-----
From: Jack Jackson [mailto:jacknos...@pebbleridge.com]

Posted At: Thursday, October 25, 2007 9:52 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
created them
Subject: Re: Accesing form controls from another class than the one
tha
created them

It is the first, where frmMain is a reference to the existing first
form that you somehow passed into the second form.

The second piece of code creates a new instance of your form, not
something that you want to do.

By the way, saying "none of them seem to work" without giving any
details is not very useful. Error message? No error but had no
effect? Had an effect you did not want?

What does the property definition in form1 look like?

On Thu, 25 Oct 2007 14:43:54 -0400, "Mike" <m...@hitnext.comwrote:
Ok, I did, buy from the 2nd form, how do I reference the forms'
property?
Is it a direct call, like:
frmMain.Myproperty = MyValue
or
Dim frm As new frmMain
With frmMain
.MyProperty = MyValue
End With
I have tried both an none of them seem to work.
Thanks!
-----Original Message-----
From: rowe_newsgroups [mailto:rowe_em...@yahoo.com]
Posted At: Thursday, October 25, 2007 2:01 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
created them
Subject: Re: Accesing form controls from another class than the one
tha
created them
On Oct 25, 11:34 am, "Mike" <m...@hitnext.comwrote:
Hi,
I have a form with some controls, and a different class that needs
to
modify some control properties at run time.
Hoy can I reference the from so I have access to its controls and
therefore being able to modify its properties?
Regards,
Mike
My personal preference is to keep the Controls private, and only
expose the necessary functionality via properties. This prevents an
outside object from being able to modify more than you want to have
modified.
For example, if you want a second form to be able to modify a label's
text property expose it like this:
////////////
Public Property MyLabelText() As String
Get
Return MyLabel.Text
End Get
Set (ByVal value As String)
MyLabel.Text = value
End Get
End Property
///////////
If instead you gave them a complete reference to the label, nothing
would stop them from calling form.MyLabel.Dispose() or something else
you didn't intend. In other words, using a property maintains
encapsulation.
Thanks,
Seth Rowe
Are you sure you have a reference to the other form? If you
instantiate an new "frmMain" like you did in a previous example, you
will not be accomplishing anything. Perhaps you could post the code
where you are retrieving the reference to frmMain?

Thanks,

Seth Rowe

Oct 27 '07 #8

P: n/a
You don't show how the variable frmCall in form2 gets set. How does
form1 pass a reference to itself to form2?

On Sat, 27 Oct 2007 01:56:55 -0400, "Mike" <mi**@hitnext.comwrote:
>
Form 1 (frmCall)

Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN.Text = value
End Set
End Property
Form 2

frmCall.TextboxWTN = "Something"
This is all I have

Thanks

-----Original Message-----
From: rowe_newsgroups [mailto:ro********@yahoo.com]
Posted At: Friday, October 26, 2007 6:36 AM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one tha
created them
Subject: Re: Accesing form controls from another class than the one tha
created them

On Oct 25, 11:06 pm, "Mike" <m...@hitnext.comwrote:
>This is the property definition:

Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN.Text = value
End Set
End Property

And from the other form I call frmMain.TextboxWTN = "Whatever"

It has no effect over the form's textbox.

Thanks

-----Original Message-----
From: Jack Jackson [mailto:jacknos...@pebbleridge.com]

Posted At: Thursday, October 25, 2007 9:52 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
>created them
Subject: Re: Accesing form controls from another class than the one
tha
>created them

It is the first, where frmMain is a reference to the existing first
form that you somehow passed into the second form.

The second piece of code creates a new instance of your form, not
something that you want to do.

By the way, saying "none of them seem to work" without giving any
details is not very useful. Error message? No error but had no
effect? Had an effect you did not want?

What does the property definition in form1 look like?

On Thu, 25 Oct 2007 14:43:54 -0400, "Mike" <m...@hitnext.comwrote:
>Ok, I did, buy from the 2nd form, how do I reference the forms'
property?
>Is it a direct call, like:
>frmMain.Myproperty = MyValue
>or
>Dim frm As new frmMain
With frmMain
.MyProperty = MyValue
End With
>I have tried both an none of them seem to work.
>Thanks!
>-----Original Message-----
From: rowe_newsgroups [mailto:rowe_em...@yahoo.com]
Posted At: Thursday, October 25, 2007 2:01 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
>created them
Subject: Re: Accesing form controls from another class than the one
tha
>created them
>On Oct 25, 11:34 am, "Mike" <m...@hitnext.comwrote:
Hi,
>I have a form with some controls, and a different class that needs
to
>modify some control properties at run time.
>Hoy can I reference the from so I have access to its controls and
therefore being able to modify its properties?
>Regards,
>Mike
>My personal preference is to keep the Controls private, and only
expose the necessary functionality via properties. This prevents an
outside object from being able to modify more than you want to have
modified.
>For example, if you want a second form to be able to modify a label's
text property expose it like this:
>////////////
Public Property MyLabelText() As String
Get
Return MyLabel.Text
End Get
Set (ByVal value As String)
MyLabel.Text = value
End Get
End Property
///////////
>If instead you gave them a complete reference to the label, nothing
would stop them from calling form.MyLabel.Dispose() or something else
you didn't intend. In other words, using a property maintains
encapsulation.
>Thanks,
>Seth Rowe

Are you sure you have a reference to the other form? If you
instantiate an new "frmMain" like you did in a previous example, you
will not be accomplishing anything. Perhaps you could post the code
where you are retrieving the reference to frmMain?

Thanks,

Seth Rowe
Oct 27 '07 #9

P: n/a
Any Example to help me

-----Original Message-----
From: Jack Jackson [mailto:ja********@pebbleridge.com]
Posted At: Saturday, October 27, 2007 10:43 AM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one tha
created them
Subject: Re: Accesing form controls from another class than the one tha
created them

You don't show how the variable frmCall in form2 gets set. How does
form1 pass a reference to itself to form2?

On Sat, 27 Oct 2007 01:56:55 -0400, "Mike" <mi**@hitnext.comwrote:
>
Form 1 (frmCall)

Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN.Text = value
End Set
End Property
Form 2

frmCall.TextboxWTN = "Something"
This is all I have

Thanks

-----Original Message-----
From: rowe_newsgroups [mailto:ro********@yahoo.com]
Posted At: Friday, October 26, 2007 6:36 AM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
>created them
Subject: Re: Accesing form controls from another class than the one tha
created them

On Oct 25, 11:06 pm, "Mike" <m...@hitnext.comwrote:
>This is the property definition:

Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN.Text = value
End Set
End Property

And from the other form I call frmMain.TextboxWTN = "Whatever"

It has no effect over the form's textbox.

Thanks

-----Original Message-----
From: Jack Jackson [mailto:jacknos...@pebbleridge.com]

Posted At: Thursday, October 25, 2007 9:52 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
>created them
Subject: Re: Accesing form controls from another class than the one
tha
>created them

It is the first, where frmMain is a reference to the existing first
form that you somehow passed into the second form.

The second piece of code creates a new instance of your form, not
something that you want to do.

By the way, saying "none of them seem to work" without giving any
details is not very useful. Error message? No error but had no
effect? Had an effect you did not want?

What does the property definition in form1 look like?

On Thu, 25 Oct 2007 14:43:54 -0400, "Mike" <m...@hitnext.comwrote:
>Ok, I did, buy from the 2nd form, how do I reference the forms'
property?
>Is it a direct call, like:
>frmMain.Myproperty = MyValue
>or
>Dim frm As new frmMain
With frmMain
.MyProperty = MyValue
End With
>I have tried both an none of them seem to work.
>Thanks!
>-----Original Message-----
From: rowe_newsgroups [mailto:rowe_em...@yahoo.com]
Posted At: Thursday, October 25, 2007 2:01 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
>created them
Subject: Re: Accesing form controls from another class than the one
tha
>created them
>On Oct 25, 11:34 am, "Mike" <m...@hitnext.comwrote:
Hi,
>I have a form with some controls, and a different class that needs
to
>modify some control properties at run time.
>Hoy can I reference the from so I have access to its controls and
therefore being able to modify its properties?
>Regards,
>Mike
>My personal preference is to keep the Controls private, and only
expose the necessary functionality via properties. This prevents an
outside object from being able to modify more than you want to have
modified.
>For example, if you want a second form to be able to modify a
label's
>text property expose it like this:
>////////////
Public Property MyLabelText() As String
Get
Return MyLabel.Text
End Get
Set (ByVal value As String)
MyLabel.Text = value
End Get
End Property
///////////
>If instead you gave them a complete reference to the label, nothing
would stop them from calling form.MyLabel.Dispose() or something
else
>you didn't intend. In other words, using a property maintains
encapsulation.
>Thanks,
>Seth Rowe

Are you sure you have a reference to the other form? If you
instantiate an new "frmMain" like you did in a previous example, you
will not be accomplishing anything. Perhaps you could post the code
where you are retrieving the reference to frmMain?

Thanks,

Seth Rowe
Nov 1 '07 #10

P: n/a
Since I have no clue what you are doing, all I can do is give an
example.

Suppose form1 creates form2, maybe in the Click event of a button:

dim frm As New Form2(Me)
frm.Show()
or
frm.ShowDialog()

In form2:

Private form1 as Form1

Public New(frm1 as Form1)

form1 = frm1

Me.InitializeComponent()

End Sub

In form 2 when you want to reference form1:

form1.xxx

On Thu, 1 Nov 2007 13:16:47 -0400, "Mike" <mi**@hitnext.comwrote:
>Any Example to help me

-----Original Message-----
From: Jack Jackson [mailto:ja********@pebbleridge.com]
Posted At: Saturday, October 27, 2007 10:43 AM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one tha
created them
Subject: Re: Accesing form controls from another class than the one tha
created them

You don't show how the variable frmCall in form2 gets set. How does
form1 pass a reference to itself to form2?

On Sat, 27 Oct 2007 01:56:55 -0400, "Mike" <mi**@hitnext.comwrote:
>>
Form 1 (frmCall)

Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN.Text = value
End Set
End Property
Form 2

frmCall.TextboxWTN = "Something"
This is all I have

Thanks

-----Original Message-----
From: rowe_newsgroups [mailto:ro********@yahoo.com]
Posted At: Friday, October 26, 2007 6:36 AM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
>>created them
Subject: Re: Accesing form controls from another class than the one tha
created them

On Oct 25, 11:06 pm, "Mike" <m...@hitnext.comwrote:
>>This is the property definition:

Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN.Text = value
End Set
End Property

And from the other form I call frmMain.TextboxWTN = "Whatever"

It has no effect over the form's textbox.

Thanks

-----Original Message-----
From: Jack Jackson [mailto:jacknos...@pebbleridge.com]

Posted At: Thursday, October 25, 2007 9:52 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
>>created them
Subject: Re: Accesing form controls from another class than the one
tha
>>created them

It is the first, where frmMain is a reference to the existing first
form that you somehow passed into the second form.

The second piece of code creates a new instance of your form, not
something that you want to do.

By the way, saying "none of them seem to work" without giving any
details is not very useful. Error message? No error but had no
effect? Had an effect you did not want?

What does the property definition in form1 look like?

On Thu, 25 Oct 2007 14:43:54 -0400, "Mike" <m...@hitnext.comwrote:

Ok, I did, buy from the 2nd form, how do I reference the forms'
property?

Is it a direct call, like:

frmMain.Myproperty = MyValue

or

Dim frm As new frmMain
With frmMain
.MyProperty = MyValue
End With

I have tried both an none of them seem to work.

Thanks!

-----Original Message-----
From: rowe_newsgroups [mailto:rowe_em...@yahoo.com]
Posted At: Thursday, October 25, 2007 2:01 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
created them
Subject: Re: Accesing form controls from another class than the one
tha
>>created them

On Oct 25, 11:34 am, "Mike" <m...@hitnext.comwrote:
Hi,

I have a form with some controls, and a different class that needs
to
>>modify some control properties at run time.

Hoy can I reference the from so I have access to its controls and
therefore being able to modify its properties?

Regards,

Mike

My personal preference is to keep the Controls private, and only
expose the necessary functionality via properties. This prevents an
outside object from being able to modify more than you want to have
modified.

For example, if you want a second form to be able to modify a
label's
>>text property expose it like this:

////////////
Public Property MyLabelText() As String
Get
Return MyLabel.Text
End Get
Set (ByVal value As String)
MyLabel.Text = value
End Get
End Property
///////////

If instead you gave them a complete reference to the label, nothing
would stop them from calling form.MyLabel.Dispose() or something
else
>>you didn't intend. In other words, using a property maintains
encapsulation.

Thanks,

Seth Rowe

Are you sure you have a reference to the other form? If you
instantiate an new "frmMain" like you did in a previous example, you
will not be accomplishing anything. Perhaps you could post the code
where you are retrieving the reference to frmMain?

Thanks,

Seth Rowe
Nov 1 '07 #11

P: n/a
OK, this is what I'm trying to do.
I have a form that requests from a singleton service.
This service has some events that needs to be wired in the client side.
Public class Form1

-here I declare a property called <TextboxAccessthat sets and gets
text text property a text box
.... from stuff

End Class
Public Class SingletonCallBack

Public sub SomeEvent

From1.TextboxAccess = "Some text"

End Sub
EndClass

This is not working for me, and there is no exceptions at all.
Even more, when I debug, I see text property of the textbox control in
form1 to get the info I pass on, but it does nor display it.

Thanks


-----Original Message-----
From: Jack Jackson [mailto:ja********@pebbleridge.com]
Posted At: Thursday, November 01, 2007 3:31 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one tha
created them
Subject: Re: Accesing form controls from another class than the one tha
created them

Since I have no clue what you are doing, all I can do is give an
example.

Suppose form1 creates form2, maybe in the Click event of a button:

dim frm As New Form2(Me)
frm.Show()
or
frm.ShowDialog()

In form2:

Private form1 as Form1

Public New(frm1 as Form1)

form1 = frm1

Me.InitializeComponent()

End Sub

In form 2 when you want to reference form1:

form1.xxx

On Thu, 1 Nov 2007 13:16:47 -0400, "Mike" <mi**@hitnext.comwrote:
>Any Example to help me

-----Original Message-----
From: Jack Jackson [mailto:ja********@pebbleridge.com]
Posted At: Saturday, October 27, 2007 10:43 AM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
>created them
Subject: Re: Accesing form controls from another class than the one tha
created them

You don't show how the variable frmCall in form2 gets set. How does
form1 pass a reference to itself to form2?

On Sat, 27 Oct 2007 01:56:55 -0400, "Mike" <mi**@hitnext.comwrote:
>>
Form 1 (frmCall)

Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN.Text = value
End Set
End Property
Form 2

frmCall.TextboxWTN = "Something"
This is all I have

Thanks

-----Original Message-----
From: rowe_newsgroups [mailto:ro********@yahoo.com]
Posted At: Friday, October 26, 2007 6:36 AM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
>>created them
Subject: Re: Accesing form controls from another class than the one
tha
>>created them

On Oct 25, 11:06 pm, "Mike" <m...@hitnext.comwrote:
>>This is the property definition:

Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN.Text = value
End Set
End Property

And from the other form I call frmMain.TextboxWTN = "Whatever"

It has no effect over the form's textbox.

Thanks

-----Original Message-----
From: Jack Jackson [mailto:jacknos...@pebbleridge.com]

Posted At: Thursday, October 25, 2007 9:52 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
>>created them
Subject: Re: Accesing form controls from another class than the one
tha
>>created them

It is the first, where frmMain is a reference to the existing first
form that you somehow passed into the second form.

The second piece of code creates a new instance of your form, not
something that you want to do.

By the way, saying "none of them seem to work" without giving any
details is not very useful. Error message? No error but had no
effect? Had an effect you did not want?

What does the property definition in form1 look like?

On Thu, 25 Oct 2007 14:43:54 -0400, "Mike" <m...@hitnext.comwrote:

Ok, I did, buy from the 2nd form, how do I reference the forms'
property?

Is it a direct call, like:

frmMain.Myproperty = MyValue

or

Dim frm As new frmMain
With frmMain
.MyProperty = MyValue
End With

I have tried both an none of them seem to work.

Thanks!

-----Original Message-----
From: rowe_newsgroups [mailto:rowe_em...@yahoo.com]
Posted At: Thursday, October 25, 2007 2:01 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the
one
>>tha
created them
Subject: Re: Accesing form controls from another class than the one
tha
>>created them

On Oct 25, 11:34 am, "Mike" <m...@hitnext.comwrote:
Hi,

I have a form with some controls, and a different class that
needs
>>to
>>modify some control properties at run time.

Hoy can I reference the from so I have access to its controls and
therefore being able to modify its properties?

Regards,

Mike

My personal preference is to keep the Controls private, and only
expose the necessary functionality via properties. This prevents an
outside object from being able to modify more than you want to have
modified.

For example, if you want a second form to be able to modify a
label's
>>text property expose it like this:

////////////
Public Property MyLabelText() As String
Get
Return MyLabel.Text
End Get
Set (ByVal value As String)
MyLabel.Text = value
End Get
End Property
///////////

If instead you gave them a complete reference to the label, nothing
would stop them from calling form.MyLabel.Dispose() or something
else
>>you didn't intend. In other words, using a property maintains
encapsulation.

Thanks,

Seth Rowe

Are you sure you have a reference to the other form? If you
instantiate an new "frmMain" like you did in a previous example, you
will not be accomplishing anything. Perhaps you could post the code
where you are retrieving the reference to frmMain?

Thanks,

Seth Rowe
Nov 2 '07 #12

P: n/a
I still don't understand.

In SingletonCallback, when you reference Form1.TextboxAccess, either
you have a property in SingletonCallback called Form1 that is set to a
reference to your instance of Form1, or TextboxAccess is a Shared
member of Form1.

If the former, how is the property Form1 set?
If the later, how does the Shared property reference the textbox?

Maybe you should either post the source for both classes, or send them
to me by e-mail.

On Fri, 2 Nov 2007 13:34:49 -0400, "Mike" <mi**@hitnext.comwrote:
>OK, this is what I'm trying to do.
I have a form that requests from a singleton service.
This service has some events that needs to be wired in the client side.
Public class Form1

-here I declare a property called <TextboxAccessthat sets and gets
text text property a text box
... from stuff

End Class
Public Class SingletonCallBack

Public sub SomeEvent

From1.TextboxAccess = "Some text"

End Sub
EndClass

This is not working for me, and there is no exceptions at all.
Even more, when I debug, I see text property of the textbox control in
form1 to get the info I pass on, but it does nor display it.

Thanks
Nov 2 '07 #13

P: n/a
Is the second one;
This is the actual code:
// This is the actual form where the textboxes to be updated reside.

Public Class frmCall

Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN = value
End Property

Public Property TextboxFirstname() As String
Get
Return Me.txtFirstname.Text
End Get
Set(ByVal value As String)
Me.txtFirstname.Text = value
End Set
End Property

End Class
// This is the class that updates the form's controls
Public Class frmCall_CallBackhandler
Implements ActiveDialerServicesProxy.IActiveDialerServicesCal lback
Public Sub OnManuallyRequestedNextCallSuccess(ByVal Prospect As
ActiveDialerServicesProxy.Prospect) Implements..

frmCall.TextboxWTN = Prospect.WTN
frmCall.TextboxFirstname = Prospect.Firstname

End Sub

End Class

Thanks for your willingness to help me. :-)



-----Original Message-----
From: Jack Jackson [mailto:ja********@pebbleridge.com]
Posted At: Friday, November 02, 2007 1:54 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one tha
created them
Subject: Re: Accesing form controls from another class than the one tha
created them

I still don't understand.

In SingletonCallback, when you reference Form1.TextboxAccess, either
you have a property in SingletonCallback called Form1 that is set to a
reference to your instance of Form1, or TextboxAccess is a Shared
member of Form1.

If the former, how is the property Form1 set?
If the later, how does the Shared property reference the textbox?

Maybe you should either post the source for both classes, or send them
to me by e-mail.

On Fri, 2 Nov 2007 13:34:49 -0400, "Mike" <mi**@hitnext.comwrote:
>OK, this is what I'm trying to do.
I have a form that requests from a singleton service.
This service has some events that needs to be wired in the client side.
Public class Form1

-here I declare a property called <TextboxAccessthat sets and gets
text text property a text box
... from stuff

End Class
Public Class SingletonCallBack

Public sub SomeEvent

From1.TextboxAccess = "Some text"

End Sub
EndClass

This is not working for me, and there is no exceptions at all.
Even more, when I debug, I see text property of the textbox control in
form1 to get the info I pass on, but it does nor display it.

Thanks
Nov 2 '07 #14

P: n/a
Is this a typo?
Me.txtWTN = value
It should be Me.txtWTN.Text. If it isn't a type then you must be
running without STRICT ON, which can lead to all kinds of errors like
this.

I still don't understand what frmCall in frmCall_CallBackhandler is.
How is it defined and how does its value get set?

Does frmCall_CallBackhander.OnManuallyRequestedNextCall Success run in
the main thread? If not that will cause problems - you can't update
UI controls from any thread except the main thread.
On Fri, 2 Nov 2007 14:48:41 -0400, "Mike" <mi**@hitnext.comwrote:
>Is the second one;
This is the actual code:
// This is the actual form where the textboxes to be updated reside.

Public Class frmCall

Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN = value
End Property

Public Property TextboxFirstname() As String
Get
Return Me.txtFirstname.Text
End Get
Set(ByVal value As String)
Me.txtFirstname.Text = value
End Set
End Property

End Class
// This is the class that updates the form's controls
Public Class frmCall_CallBackhandler
Implements ActiveDialerServicesProxy.IActiveDialerServicesCal lback
Public Sub OnManuallyRequestedNextCallSuccess(ByVal Prospect As
ActiveDialerServicesProxy.Prospect) Implements..

frmCall.TextboxWTN = Prospect.WTN
frmCall.TextboxFirstname = Prospect.Firstname

End Sub

End Class

Thanks for your willingness to help me. :-)



-----Original Message-----
From: Jack Jackson [mailto:ja********@pebbleridge.com]
Posted At: Friday, November 02, 2007 1:54 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one tha
created them
Subject: Re: Accesing form controls from another class than the one tha
created them

I still don't understand.

In SingletonCallback, when you reference Form1.TextboxAccess, either
you have a property in SingletonCallback called Form1 that is set to a
reference to your instance of Form1, or TextboxAccess is a Shared
member of Form1.

If the former, how is the property Form1 set?
If the later, how does the Shared property reference the textbox?

Maybe you should either post the source for both classes, or send them
to me by e-mail.

On Fri, 2 Nov 2007 13:34:49 -0400, "Mike" <mi**@hitnext.comwrote:
>>OK, this is what I'm trying to do.
I have a form that requests from a singleton service.
This service has some events that needs to be wired in the client side.
Public class Form1

-here I declare a property called <TextboxAccessthat sets and gets
text text property a text box
... from stuff

End Class
Public Class SingletonCallBack

Public sub SomeEvent

From1.TextboxAccess = "Some text"

End Sub
EndClass

This is not working for me, and there is no exceptions at all.
Even more, when I debug, I see text property of the textbox control in
form1 to get the info I pass on, but it does nor display it.

Thanks
Nov 2 '07 #15

P: n/a
Yes, that is a typo.
It actually is me.txtWTN.Text = value

frmCall in frmCall_CallBackhandler it's a direct reference to the form
I'm trying to update.

I guess frmCall_CallBackhander.OnManuallyRequestedNextCall Success runs
on the main thread.
How can I find out?

Thnaks
-----Original Message-----
From: Jack Jackson [mailto:ja********@pebbleridge.com]
Posted At: Friday, November 02, 2007 7:12 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one tha
created them
Subject: Re: Accesing form controls from another class than the one tha
created them

Is this a typo?
Me.txtWTN = value
It should be Me.txtWTN.Text. If it isn't a type then you must be
running without STRICT ON, which can lead to all kinds of errors like
this.

I still don't understand what frmCall in frmCall_CallBackhandler is.
How is it defined and how does its value get set?

Does frmCall_CallBackhander.OnManuallyRequestedNextCall Success run in
the main thread? If not that will cause problems - you can't update
UI controls from any thread except the main thread.
On Fri, 2 Nov 2007 14:48:41 -0400, "Mike" <mi**@hitnext.comwrote:
>Is the second one;
This is the actual code:
// This is the actual form where the textboxes to be updated reside.

Public Class frmCall

Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN = value
End Property

Public Property TextboxFirstname() As String
Get
Return Me.txtFirstname.Text
End Get
Set(ByVal value As String)
Me.txtFirstname.Text = value
End Set
End Property

End Class
// This is the class that updates the form's controls
Public Class frmCall_CallBackhandler
Implements ActiveDialerServicesProxy.IActiveDialerServicesCal lback
Public Sub OnManuallyRequestedNextCallSuccess(ByVal Prospect As
ActiveDialerServicesProxy.Prospect) Implements..

frmCall.TextboxWTN = Prospect.WTN
frmCall.TextboxFirstname = Prospect.Firstname

End Sub

End Class

Thanks for your willingness to help me. :-)



-----Original Message-----
From: Jack Jackson [mailto:ja********@pebbleridge.com]
Posted At: Friday, November 02, 2007 1:54 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
>created them
Subject: Re: Accesing form controls from another class than the one tha
created them

I still don't understand.

In SingletonCallback, when you reference Form1.TextboxAccess, either
you have a property in SingletonCallback called Form1 that is set to a
reference to your instance of Form1, or TextboxAccess is a Shared
member of Form1.

If the former, how is the property Form1 set?
If the later, how does the Shared property reference the textbox?

Maybe you should either post the source for both classes, or send them
to me by e-mail.

On Fri, 2 Nov 2007 13:34:49 -0400, "Mike" <mi**@hitnext.comwrote:
>>OK, this is what I'm trying to do.
I have a form that requests from a singleton service.
This service has some events that needs to be wired in the client
side.
>>

Public class Form1

-here I declare a property called <TextboxAccessthat sets and gets
text text property a text box
... from stuff

End Class
Public Class SingletonCallBack

Public sub SomeEvent

From1.TextboxAccess = "Some text"

End Sub
EndClass

This is not working for me, and there is no exceptions at all.
Even more, when I debug, I see text property of the textbox control in
form1 to get the info I pass on, but it does nor display it.

Thanks
Nov 3 '07 #16

P: n/a
I still don't understand your code. There is no such thing as a
direct reference to an instance of a class. There are two ways to
reference an item. Either you have a reference in a variable to an
instance of a class, or you access a shared method or property. Since
TextboxFirstName is not shared, it must be accessed by reference to an
instance of a class.

I think somehow, in frmCall_CallBackhandler, there must be a variable
named frmCall that contains a reference to an instance of the frmCall
class that is not the one that is visible.

On Fri, 2 Nov 2007 23:41:11 -0400, "Mike" <mi**@hitnext.comwrote:
>Yes, that is a typo.
It actually is me.txtWTN.Text = value

frmCall in frmCall_CallBackhandler it's a direct reference to the form
I'm trying to update.

I guess frmCall_CallBackhander.OnManuallyRequestedNextCall Success runs
on the main thread.
How can I find out?

Thnaks
-----Original Message-----
From: Jack Jackson [mailto:ja********@pebbleridge.com]
Posted At: Friday, November 02, 2007 7:12 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one tha
created them
Subject: Re: Accesing form controls from another class than the one tha
created them

Is this a typo?
> Me.txtWTN = value

It should be Me.txtWTN.Text. If it isn't a type then you must be
running without STRICT ON, which can lead to all kinds of errors like
this.

I still don't understand what frmCall in frmCall_CallBackhandler is.
How is it defined and how does its value get set?

Does frmCall_CallBackhander.OnManuallyRequestedNextCall Success run in
the main thread? If not that will cause problems - you can't update
UI controls from any thread except the main thread.
On Fri, 2 Nov 2007 14:48:41 -0400, "Mike" <mi**@hitnext.comwrote:
>>Is the second one;
This is the actual code:
// This is the actual form where the textboxes to be updated reside.

Public Class frmCall

Public Property TextboxWTN() As String
Get
Return Me.txtWTN.Text
End Get
Set(ByVal value As String)
Me.txtWTN = value
End Property

Public Property TextboxFirstname() As String
Get
Return Me.txtFirstname.Text
End Get
Set(ByVal value As String)
Me.txtFirstname.Text = value
End Set
End Property

End Class
// This is the class that updates the form's controls
Public Class frmCall_CallBackhandler
Implements ActiveDialerServicesProxy.IActiveDialerServicesCal lback
Public Sub OnManuallyRequestedNextCallSuccess(ByVal Prospect As
ActiveDialerServicesProxy.Prospect) Implements..

frmCall.TextboxWTN = Prospect.WTN
frmCall.TextboxFirstname = Prospect.Firstname

End Sub

End Class

Thanks for your willingness to help me. :-)



-----Original Message-----
From: Jack Jackson [mailto:ja********@pebbleridge.com]
Posted At: Friday, November 02, 2007 1:54 PM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Accesing form controls from another class than the one
tha
>>created them
Subject: Re: Accesing form controls from another class than the one tha
created them

I still don't understand.

In SingletonCallback, when you reference Form1.TextboxAccess, either
you have a property in SingletonCallback called Form1 that is set to a
reference to your instance of Form1, or TextboxAccess is a Shared
member of Form1.

If the former, how is the property Form1 set?
If the later, how does the Shared property reference the textbox?

Maybe you should either post the source for both classes, or send them
to me by e-mail.

On Fri, 2 Nov 2007 13:34:49 -0400, "Mike" <mi**@hitnext.comwrote:
>>>OK, this is what I'm trying to do.
I have a form that requests from a singleton service.
This service has some events that needs to be wired in the client
side.
>>>

Public class Form1

-here I declare a property called <TextboxAccessthat sets and gets
text text property a text box
... from stuff

End Class
Public Class SingletonCallBack

Public sub SomeEvent

From1.TextboxAccess = "Some text"

End Sub
EndClass

This is not working for me, and there is no exceptions at all.
Even more, when I debug, I see text property of the textbox control in
form1 to get the info I pass on, but it does nor display it.

Thanks
Nov 3 '07 #17

This discussion thread is closed

Replies have been disabled for this discussion.