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

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

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
 
Mike said:
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
 
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
 
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:[email protected]]
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

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
 
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?

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:[email protected]]
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

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
 
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:[email protected]]
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?

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:[email protected]]
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

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
 
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:[email protected]]

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?

Ok, I did, buy from the 2nd form, how do I reference the forms'
property?
Is it a direct call, like:
frmMain.Myproperty = MyValue

Dim frm As new frmMain
With frmMain
.MyProperty = MyValue
End With
I have tried both an none of them seem to work.

-----Original Message-----
From: rowe_newsgroups [mailto:[email protected]]
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
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.

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
 
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:[email protected]]
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

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:[email protected]]

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?

Ok, I did, buy from the 2nd form, how do I reference the forms'
property?
Is it a direct call, like:
frmMain.Myproperty = MyValue

Dim frm As new frmMain
With frmMain
.MyProperty = MyValue
End With
I have tried both an none of them seem to work.

-----Original Message-----
From: rowe_newsgroups [mailto:[email protected]]
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
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.

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
 
You don't show how the variable frmCall in form2 gets set. How does
form1 pass a reference to itself to form2?

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:[email protected]]
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

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:[email protected]]

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?

Ok, I did, buy from the 2nd form, how do I reference the forms'
property?
Is it a direct call, like:
frmMain.Myproperty = MyValue

Dim frm As new frmMain
With frmMain
.MyProperty = MyValue
End With
I have tried both an none of them seem to work.

-----Original Message-----
From: rowe_newsgroups [mailto:[email protected]]
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
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?


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.

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
 
Any Example to help me

-----Original Message-----
From: Jack Jackson [mailto:[email protected]]
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?

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:[email protected]]
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

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:[email protected]]

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?

Ok, I did, buy from the 2nd form, how do I reference the forms'
property?
Is it a direct call, like:
frmMain.Myproperty = MyValue

Dim frm As new frmMain
With frmMain
.MyProperty = MyValue
End With
I have tried both an none of them seem to work.

-----Original Message-----
From: rowe_newsgroups [mailto:[email protected]]
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
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?


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.

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
 
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

Any Example to help me

-----Original Message-----
From: Jack Jackson [mailto:[email protected]]
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?

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:[email protected]]
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

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:[email protected]]

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?


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:[email protected]]
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

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
 
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 <TextboxAccess> that 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:[email protected]]
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

Any Example to help me

-----Original Message-----
From: Jack Jackson [mailto:[email protected]]
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?

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:[email protected]]
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

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:[email protected]]

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?


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:[email protected]]
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

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
 
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.
 
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.IActiveDialerServicesCallback


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:[email protected]]
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.
 
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.OnManuallyRequestedNextCallSuccess run in
the main thread? If not that will cause problems - you can't update
UI controls from any thread except the main thread.


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.IActiveDialerServicesCallback


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:[email protected]]
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.

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 <TextboxAccess> that 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
 
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.OnManuallyRequestedNextCallSuccess runs
on the main thread.
How can I find out?

Thnaks


-----Original Message-----
From: Jack Jackson [mailto:[email protected]]
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.OnManuallyRequestedNextCallSuccess run in
the main thread? If not that will cause problems - you can't update
UI controls from any thread except the main thread.


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.IActiveDialerServicesCallback


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:[email protected]]
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.

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 <TextboxAccess> that 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
 
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.

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.OnManuallyRequestedNextCallSuccess runs
on the main thread.
How can I find out?

Thnaks


-----Original Message-----
From: Jack Jackson [mailto:[email protected]]
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.OnManuallyRequestedNextCallSuccess run in
the main thread? If not that will cause problems - you can't update
UI controls from any thread except the main thread.


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.IActiveDialerServicesCallback


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:[email protected]]
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.

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 <TextboxAccess> that 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
 
Back
Top