References to Controls on Open Forms In VB.Net 2003

  • Thread starter Thread starter Atley
  • Start date Start date
A

Atley

How do I reference controls on an open form from another form? I need to
force controls to refresh and/or run code that is private to that form.

Any help is appreciated.

Atley
 
Use the open Form's instance:

MyForm form1 = new MyForm();
MyForm form2 = new MyForm;
....
form1.myText = "hello";
form2.myText = "there";
 
Yes, but what if one form is already open... Do I have to create a Public
(Global) varible to hold that instance of the form?
 
You have to get the reference to it somehow. Either use a global or pass it
to the new Form.
 
How did the form get open? You can save a reference to a form when you
create it:

MyFormVar = new MyForm

To pass something from one form to another you can declare a Public variable
in one form and set it from the other:

Form 1:
Public FormProperty as MyForm

Form 2:
MyFormVar = new Form1
Form1.FormProperty = MyFormVar
 
Depends on how you want to do it. You could add a ctor to the form that
needs a reference like this:

class FormA : Form
{
void DoSomething()
{
}
}

class FormB : Form
{
FormB(FormA otherForm)
{
otherForm.DoSomething();
}
}

....
FormA formA = new FormA();
FormB formB = new FormB(formA);
 
I have absolutely no idea how this works... How would I use this in VB? It
just doesn't make sense to me...

Can you tell me or perhaps point me to an example in VB?

Thanks...

Atley
 
This is pretty basic OOP, so I'll first suggest that you get an intro to
VB.NET book. The largest learning curve you'll have (and this is true with
most VB developers) is to learn how true OOP works. Once you've got your
brain around that, it will make sense.

At any rate, here's the code in VB (with some work to make it more clear).

Class FormA Inherits Form
....
Private Sub DoSomething()
...
End Sub
....
End Class

Class FormB Inherits Form
Dim FormA As localReference
....
Private Sub New(ByVal otherForm As FormA)
localReference = otherForm
End Sub

Private Sub UseOtherForm()
localReference.DoSomething()
End Sub
....
End Class

....
Dim formA As FormA = New FormA()
Dim formB As FormB = New FormB(formA)

-Chris
 
Thanks, That made much more sense to me... I have the VB.Net book, but as
with most older developers, I have been reading it as I need it... I find
that a lot of the things in it do not apply to CF though.


Also, where can I download the version 2 of the CF? Do i need it for my
Visual Studio? I can't find it anywhere for my PPC either, I looked in the
developer section of the MS site, I must be missing something.

Thank you again for all of your help,
Atley
 
Atley,
you can find the .NET Compact Framework 1.0 SP2 Redist package
at the following link:

http://www.microsoft.com/downloads/details.aspx?FamilyID=359ea6da-fc5d-41cc-
ac04-7bb50a134556&DisplayLang=en
It was released on 12/16/2003. Hope this helps.

Jim


----
From: "Atley" <[email protected]>
Subject: Re: References to Controls on Open Forms In VB.Net 2003
Date: Thu, 15 Jan 2004 20:14:29 -0500
Newsgroups: microsoft.public.dotnet.framework.compactframework

Ok, still haven't found it....

Atley
 
Thanks....


Jim Suplizio said:
Atley,
you can find the .NET Compact Framework 1.0 SP2 Redist package
at the following link:

http://www.microsoft.com/downloads/details.aspx?FamilyID=359ea6da-fc5d-41cc-
ac04-7bb50a134556&DisplayLang=en
It was released on 12/16/2003. Hope this helps.

Jim


----
From: "Atley" <[email protected]>
Subject: Re: References to Controls on Open Forms In VB.Net 2003
Date: Thu, 15 Jan 2004 20:14:29 -0500
Newsgroups: microsoft.public.dotnet.framework.compactframework

Ok, still haven't found it....

Atley
 
Back
Top