Home All Groups Group Topic Archive Search About

How to get a form's property value from a class?

Author
22 Nov 2006 1:55 AM
Dean Slindee
I have a form whose Property value I need to get at from a class (contained
in another project, same solution).

Here is the form's property:

   Private booIsInsert As Boolean = False

   Public Property IsInsert() As Boolean

      Get

         Return booIsInsert

      End Get

      Set(ByVal Value As Boolean)

         booIsInsert = Value

      End Set

   End Property



Here is the class's function that needs the property value:

   Public Shared Sub FormDataChanged(ByVal sender As System.Object)

      Dim frmParent As Form

      frmParent = sender.ParentForm

      If Not frmParent.IsInsert Then 'SYNTAX ERROR line

         Dim ctl As Control

         ctl = CType(frmParent.Controls.Item("btnUpdate"), Control)

         Call FrameButtonPaintFlat(frmParent, CType(ctl, Control)) 'green
frame around button

      End If



Syntax error message: "IsInsert is not a member of
System.Windows.Forms.Form"

I understand the error, but is there *any* way to reference the frmParent
instance and get the IsInsert property value?

Or some other approach?



Thanks in advance.

Dean S

Author
22 Nov 2006 3:08 AM
RobinS
You probably need to add a reference to
the project containing the class in which
you want to access that form's property.
(Did you get that?)

To be clearer (I hope), an example:

1) Project 1, has Form1 with property IsInsert.
2) Project 2, has Class1 that wants to access
   Form1's property IsInsert.

Open Project2's properties and click on References.
THen click on Add. Choose the Projects tab, and
select Project1.

Then on the bottom of the screen, where it has
Imported Namespaces, find Project1 in the list
and check it (you'll have to click it twice).
Not Project1.My or Project1.My.Resources,
just Project1.

*Now* you should be able to access Form1.IsInsert.

Good luck.
Robin S.
----------------------------------------

Show quoteHide quote
"Dean Slindee" <slin***@charter.net> wrote in message
news:2aO8h.263$MY7.29@newsfe06.lga...
>I have a form whose Property value I need to get at from a class (contained
>in another project, same solution).
>
> Here is the form's property:
>
>   Private booIsInsert As Boolean = False
>
>   Public Property IsInsert() As Boolean
>
>      Get
>
>         Return booIsInsert
>
>      End Get
>
>      Set(ByVal Value As Boolean)
>
>         booIsInsert = Value
>
>      End Set
>
>   End Property
>
>
>
> Here is the class's function that needs the property value:
>
>   Public Shared Sub FormDataChanged(ByVal sender As System.Object)
>
>      Dim frmParent As Form
>
>      frmParent = sender.ParentForm
>
>      If Not frmParent.IsInsert Then 'SYNTAX ERROR line
>
>         Dim ctl As Control
>
>         ctl = CType(frmParent.Controls.Item("btnUpdate"), Control)
>
>         Call FrameButtonPaintFlat(frmParent, CType(ctl, Control)) 'green
> frame around button
>
>      End If
>
>
>
> Syntax error message: "IsInsert is not a member of
> System.Windows.Forms.Form"
>
> I understand the error, but is there *any* way to reference the frmParent
> instance and get the IsInsert property value?
>
> Or some other approach?
>
>
>
> Thanks in advance.
>
> Dean S
>
>
>
>
Author
22 Nov 2006 3:54 AM
Michael C
"Dean Slindee" <slin***@charter.net> wrote in message
news:2aO8h.263$MY7.29@newsfe06.lga...
>I have a form whose Property value I need to get at from a class (contained
>in another project, same solution).

I'd suggest you're doing something wrong. In all my years of programming I
don't think I've ever done this or needed to do this. The form should pass
whatever information it needs to the class so the class can perform its
task. Can you explain more what you're doing?

If you really need to do this I'm presuming Robin's answer won't help
because the project with the form already has a reference to the project
with the class, so you can reference the other way. But what you can do is
define an interface in the project with the class and have the form
implement that interface.

Michael
Author
22 Nov 2006 5:29 PM
RobinS
If you want project1 to reference something in project2,
you must add a reference to project1, even if project2
has a reference to project1. It's project-specific, and
project1 doesn't know about project2's reference to project1.
Did I use the word project in there enough times? ;-)

Robin S.
--------------------
Show quoteHide quote
"Michael C" <nospam@nospam.com> wrote in message
news:eESGykeDHHA.952@TK2MSFTNGP03.phx.gbl...
> "Dean Slindee" <slin***@charter.net> wrote in message
> news:2aO8h.263$MY7.29@newsfe06.lga...
>>I have a form whose Property value I need to get at from a class
>>(contained in another project, same solution).
>
> I'd suggest you're doing something wrong. In all my years of programming I
> don't think I've ever done this or needed to do this. The form should pass
> whatever information it needs to the class so the class can perform its
> task. Can you explain more what you're doing?
>
> If you really need to do this I'm presuming Robin's answer won't help
> because the project with the form already has a reference to the project
> with the class, so you can reference the other way. But what you can do is
> define an interface in the project with the class and have the form
> implement that interface.
>
> Michael
>
Author
26 Nov 2006 10:09 PM
Michael C
"RobinS" <RobinS@NoSpam.yah.none> wrote in message
news:ALednTI8RryMFPnYnZ2dnUVZ_smdnZ2d@comcast.com...
> If you want project1 to reference something in project2,
> you must add a reference to project1, even if project2
> has a reference to project1. It's project-specific, and
> project1 doesn't know about project2's reference to project1.
> Did I use the word project in there enough times? ;-)

For a start you can't add a reference to an exe project. Even if both
projects were dlls I doubt you could add a circular reference. Even if you
could this would be bad practice. Which would you compile first?

Michael
Author
26 Nov 2006 10:32 PM
RobinS
I assumed he was talking about having multiple project
inside one solution. If I misunderstood, then never mind. :-)

Robin S.
----------------------------------
Show quoteHide quote
"Michael C" <nospam@nospam.com> wrote in message
news:ubwdLbaEHHA.4024@TK2MSFTNGP04.phx.gbl...
> "RobinS" <RobinS@NoSpam.yah.none> wrote in message
> news:ALednTI8RryMFPnYnZ2dnUVZ_smdnZ2d@comcast.com...
>> If you want project1 to reference something in project2,
>> you must add a reference to project1, even if project2
>> has a reference to project1. It's project-specific, and
>> project1 doesn't know about project2's reference to project1.
>> Did I use the word project in there enough times? ;-)
>
> For a start you can't add a reference to an exe project. Even if both
> projects were dlls I doubt you could add a circular reference. Even if you
> could this would be bad practice. Which would you compile first?
>
> Michael
>
Author
26 Nov 2006 11:15 PM
Michael C
"RobinS" <RobinS@NoSpam.yah.none> wrote in message
news:XLOdnacWmsCYi_fYnZ2dnUVZ_s6dnZ2d@comcast.com...
>I assumed he was talking about having multiple project
> inside one solution. If I misunderstood, then never mind. :-)

He was. For projects in the same solution I doubt you can add a circular
reference.

Michael
Author
27 Nov 2006 3:38 AM
RobinS
"Michael C" <nospam@nospam.com> wrote in message
news:%23fmYGAbEHHA.3596@TK2MSFTNGP03.phx.gbl...
> "RobinS" <RobinS@NoSpam.yah.none> wrote in message
> news:XLOdnacWmsCYi_fYnZ2dnUVZ_s6dnZ2d@comcast.com...
>>I assumed he was talking about having multiple project
>> inside one solution. If I misunderstood, then never mind. :-)
>
> He was. For projects in the same solution I doubt you can add a circular
> reference.
>
> Michael

Yes, you're absolutely right. I must have had some temporary
insanity going on there, to think that would work. My mistake.
Thanks for clarifying.

Robin S.
Author
22 Nov 2006 5:16 AM
Cor Ligthert [MVP]
Dean,

I have almost the same idea as Michael, even more, it seems that you want to
give the property at a certain moment to the class. I think that than a
method is more sufficient because than the given data can be processed.

Cor

Show quoteHide quote
"Dean Slindee" <slin***@charter.net> schreef in bericht
news:2aO8h.263$MY7.29@newsfe06.lga...
>I have a form whose Property value I need to get at from a class (contained
>in another project, same solution).
>
> Here is the form's property:
>
>   Private booIsInsert As Boolean = False
>
>   Public Property IsInsert() As Boolean
>
>      Get
>
>         Return booIsInsert
>
>      End Get
>
>      Set(ByVal Value As Boolean)
>
>         booIsInsert = Value
>
>      End Set
>
>   End Property
>
>
>
> Here is the class's function that needs the property value:
>
>   Public Shared Sub FormDataChanged(ByVal sender As System.Object)
>
>      Dim frmParent As Form
>
>      frmParent = sender.ParentForm
>
>      If Not frmParent.IsInsert Then 'SYNTAX ERROR line
>
>         Dim ctl As Control
>
>         ctl = CType(frmParent.Controls.Item("btnUpdate"), Control)
>
>         Call FrameButtonPaintFlat(frmParent, CType(ctl, Control)) 'green
> frame around button
>
>      End If
>
>
>
> Syntax error message: "IsInsert is not a member of
> System.Windows.Forms.Form"
>
> I understand the error, but is there *any* way to reference the frmParent
> instance and get the IsInsert property value?
>
> Or some other approach?
>
>
>
> Thanks in advance.
>
> Dean S
>
>
>
>