Cross form control reference

L

Larry Tate

I have been at this for over a month and have finally broke down and decided
to post having exhausted all other resources.


I have tried all the methods of talking to controls on different forms.

I have tried ...
dim _Form1 as New Form1()
using properties in the globals file
Using imports in the top of my code.

All of which have failed. They do not give errors. They just don't change
anything. I need to be able to command the Form1 with Form2, like changing
focus and enabling.

Here is my scenario ...

MDIMainForm->Form1->Form2


In MDIMainForm ...
------------------------------------------
Dim _Form1 As New Form1()
_Form1.MdiParent = Me
_Form1.Show()
_Form1 = Nothing
------------------------------------------


In Form 1...
------------------------------------------
Dim _Form2 As New Form2()
_Form2.MdiParent = MDIMainForm.ActiveForm
_Form2.Show()
_Form2 = Nothing
------------------------------------------


In Form 2
------------------------------------------
This is where is have tried to ref Form1
------------------------------------------


Maybe I am launching form2 the wrong way. If I don't make MDIForm the Parent
then Form2 runs wild.
Big FYI .. I need Form2 to be held be the MDIForm and be controlled be
Form1.

Sys Info
Windows XP Pro Sp1
Latest .NET 1.1
Visual Studio.NET



Thanks for any help anyone can give.
Me
 
J

Jan Tielens

A lot of people are having this kind of problems, mostly due to the fact
that this was different in VB6. In VB.NET you need a reference to another
form if you want to get data from that form for example. Luckily there is a
very good article on MSDN describing these kind of problems:
http://msdn.microsoft.com/library/en-us/dv_vstechart/html/vbtchworkingwithmu
ltipleformsinvisualbasicnetupgradingtonet.asp
Describes how working with multiple forms has changed from previous editions
of Microsoft Visual Basic and illustrates several key techniques, including
displaying a second form, changing the appearance of another form, and using
a form as a dialog.

If you have more questions, please ask them!

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
 
H

Herfried K. Wagner [MVP]

* "Larry Tate said:
I have been at this for over a month and have finally broke down and decided
to post having exhausted all other resources.

I have tried all the methods of talking to controls on different forms.

I have tried ...
dim _Form1 as New Form1()
using properties in the globals file
Using imports in the top of my code.

All of which have failed. They do not give errors. They just don't change
anything. I need to be able to command the Form1 with Form2, like changing
focus and enabling. [...]
------------------------------------------
Dim _Form2 As New Form2()
_Form2.MdiParent = MDIMainForm.ActiveForm
_Form2.Show()
_Form2 = Nothing

I don't understand the code above. Why do you assign the 'ActiveForm'
property to the 'MdiParent' property?
 
L

Larry Tate

Because if I don't set the ActiveForm to the MDI then Form2 is not held
within the MDIForm. It launches outside the MDIForm.I could be doing this
wrong. I dunno.

Am I launching the forms properly? If not why is it wrong.

Also ... Thanks for the reply Jan :)

Thanks,
Larry




Herfried K. Wagner said:
* "Larry Tate said:
I have been at this for over a month and have finally broke down and decided
to post having exhausted all other resources.

I have tried all the methods of talking to controls on different forms.

I have tried ...
dim _Form1 as New Form1()
using properties in the globals file
Using imports in the top of my code.

All of which have failed. They do not give errors. They just don't change
anything. I need to be able to command the Form1 with Form2, like changing
focus and enabling. [...]
------------------------------------------
Dim _Form2 As New Form2()
_Form2.MdiParent = MDIMainForm.ActiveForm
_Form2.Show()
_Form2 = Nothing

I don't understand the code above. Why do you assign the 'ActiveForm'
property to the 'MdiParent' property?
 
L

Larry Tate

Still at the same point. I tried to use this code here from the article ...

Private Shared m_vb6FormDefInstance As Form1
Private Shared m_InitializingDefInstance As Boolean
Public Shared Property DefInstance() As Form1
Get
If m_vb6FormDefInstance Is Nothing OrElse
m_vb6FormDefInstance.IsDisposed Then
m_InitializingDefInstance = True
m_vb6FormDefInstance = New Form1()
m_InitializingDefInstance = False
End If
DefInstance = m_vb6FormDefInstance
End Get
Set(ByVal Value As Form1)
m_vb6FormDefInstance = Value
End Set
End Property


I inserted this in head of my form2 to ref form1.
I tried DefInstance.TextBox.Text = "Test"

And as usual, no error and no change.

Can someone send me a test project that does what I am trying to do?
(e-mail address removed)

Thanks,
Larry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top