Show Hidden Form

  • Thread starter Thread starter Jim Burns
  • Start date Start date
J

Jim Burns

How do I Get a ref to my hidden Object like a Form1 When I try to Show the
Form1 from Form2 I can not get a reference to the same instance.
I can Show New Form1's but I cant unhide The one I Hid
Thanks again for the Imagelist Answer. it worked
 
Jim,

Can you show some code, because this seems a little bit strange.
A form can be used as MDI child, MDI parent, with show and showdialog.
All have different ways of using them (getting the parents and the
children).

Cor
 
Not MDI
in vb6 Code would be.
If you have two Forms Form1 and Form2 and you startup with Form1

Private Sub Button1_Click() '"Button on form1"
Form2.Show
me.Hide
End Sub

Private Sub Button1_Click() "Button on form2
Form1.Show ' Form1 would show with any info entered on the form before
I Called Hide.
Unload Me
End Sub

In .net I have to Dim Form2 as New Form2
Form2.Show
My ? is If I hide an instance of Form1 or Form2 How can I access the Hidden
Form. And not a New Instance of it.
 
Jim,

There are a lot of posibilities for this, however this is in my opinon the
most easy one in this case.

\\\
Me.Hide()
Dim frm2 As New Form2
frm2.ShowDialog(me)
frm2.Dispose()
Me.Show()
///

I hope this helps?

Cor
 
I just Started using MDI in .net Im Having The same Problem ,not Calling a
hidden form The problem is only getting 1 instance of form2.
To show a child or in a non-MDI app to show a form do I have to (Dim frm2 as
NEW? Form2) I only want One Form2 & One Form3 and so on .
Can I call a form2 with out the "New" key word. And if not how do I get only
one instance of Form2 in MDI or SDI.
In the Mdi App I can work around it by setting up a boolForm=False To see if
Form1 was loaded Then set it back to false when it closes .
 
Thank you that's a way to work around it.
I was hoping there was a way to reference Form 1 from form 2
Dim Form1 As New Form1()

Me.TextBox1.Text = Form1.TextBox1.Text

I can work around this too ,But I wanted to know if I had to.
I know there is no Forms collection in .net and I could make one.
But my ? is simple can I Show a Form2 with out creating a NEW instance of
one Every time I want to show it.
 
Jim,

"me" means just "my" or "this.object"

So when you say
dim frm1 as new form1 you say, create from the form1 class an instance
(object)
(The startup has a build in sub main where this happens).

The same is when you say
dim frm2 as new form2

When you would say

dim frm2 as form
dim frm3 as new form3
frm2 = frm3
than frm2 is frm3 however frm3 is as well frm3

Form1, Form2 and Form3 are classes in this
me is an object
frm2 is an objects
frm3 is an objects

In VBclassic is this a little bit mixed up by trying to make it easier.

You understand probably already what I want to say, people who did
VB(classic) are confused by the behaviour as it is now, however is in VBNet
the same as in C# and more other languages.

I thought it would be better to write this than give you an example in this.

I hope it helps something,

Cor
 
Jim,

There are by the way possibilities to reference the object instanced from
form1 in Frm2, however it is not good practise because Frm2 comes than
directly completly dependend from the Form1 object so when your change
something than you can have the conflicts that OOP should prevents.

Better is in my opinion to pass the value by overloading new or in my
opinion better, properties in Form2 that are filled before the show.

I hope this helps?

Cor
 
Thank you I totally understand about creating an object from a forms class I
just wanted to know if it was possible to Reference The Object From another
Object. Its for a small app Ill just keep it in VB6 .I just Program for fun
and .net isn't much fun.
I'm starting to think maybe the vb (Classic) people are right. If I did this
for a living I would be pissed.
 
Jim,

I know you position in this and you are not the first, I even remember the
answer from Noozer on a previous message from you.

And when you see how much I post than you would understand that that means
that this is extra ordinary. However it is computing so I can be wrong.

Not something angry of course, just that we should not take everything to
serious.

:-)

Cor
 
Hi Jim!

I used to be a VBClassic programmer and I have to say that dotnet is much
more fun. I also only program for fun and I would never go back to VBClassic
to now.

I know this is not exactly your scenario, but hopefully, it will help you do
what you want.

You have a Form2 which you wish to hide and show from your MDI MainForm and
only have one Instance.
When the form is closed you can no longer access it because it has been
disposed. You wish the form to hide rather than close so that it can
continue to be used by your application.

It's very simple, but slightly different to the way you would do it in
VBClassic.

\\\
Private WithEvents MyForm2 as New Form2

Protected Sub MainForm_Load(...) Handles MyBase.Load
MyForm2.MDIParent = Me
End Sub

Private Sub SomeButton_Click(...) Handles SomeButton.Click
MyForm2.Visible = True
End Sub

Protected Sub MyForm2_Closing(...)Handles MyForm2.Closing
MyForm2.Visible = False
e.Cancel = True
End Sub
///

Another method you could use is to add a module to your project.

\\\
Module FormObjects

Public WithEvents MyForm1 As New Form1
Public WithEvents MyForm2 As New Form2

Private Sub MyForm_Closing(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles MyForm1.Closing,
MyForm2.Closing
DirectCast(Sender,Form).Visible = False
e.Cancel = True
End Sub

End Module
///

Now MyForm1 and MyForm2 can be accessed from any form in your app.

Is this the sort of thing you were looking for?
 
Couldn't get it to work I think the answer to my? is NO.
You cant reference The Running instance of a form or its controls like in
vb6.
"Mick Doherty"
 
It's not the same as VB6, don't expect to write VB6 code for VB.Net.

Try to post a simple example of what you are trying to do.

With my module Example you can access any control on either MyForm1 or
MyForm2 from any other form.
In order to access the instance of a form you must set a reference to it.
In the module example I created the variable MyForm1 and set it to a new
Instance of Form1 and similar with MyForm2.

You can then click Button1 on the Instance of Form1 from any other form like
so:
\\\
MyForm1.Button1.PerformClick()
///

What was it that you could not get to work?
 
I new there had to be a simple way to only have one instance of every form
in your app and be able to effect the form and controls exactly like in vb6.
So I Finally figured out an easy way to do it.

Module Module1

Public WithEvents frm1 As New Form1()

Public WithEvents frm2 As New Form2()

Public jim As String

Public Sub main()

Application.Run(frm1)

End Sub

End Module

____________________________________________________________________________
_________

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

frm2.Show()

Me.Hide()

End Sub

_________________"Code in
Form1_______________________________________________________________________
_______

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

frm1.Visible = True

End Sub

________________"Code in
Forn2_______________________________________________________________________
_____________

"Mick Doherty"
 
Didnt need to use WithEvents Key Word
Jim Burns said:
I new there had to be a simple way to only have one instance of every form
in your app and be able to effect the form and controls exactly like in vb6.
So I Finally figured out an easy way to do it.

Module Module1

Public WithEvents frm1 As New Form1()

Public WithEvents frm2 As New Form2()

Public jim As String

Public Sub main()

Application.Run(frm1)

End Sub

End Module

____________________________________________________________________________
_________

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

frm2.Show()

Me.Hide()

End Sub

_________________"Code in
Form1_______________________________________________________________________
_______

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

frm1.Visible = True

End Sub

________________"Code in
Forn2_______________________________________________________________________
_____________

"Mick Doherty"
message news:eIac5W2%[email protected]...
 
I'm glad you got it working.
I used WithEvents in the original example so I could intercept the Closing
of the Forms Instance and hide it, instead of close it, when a user clicked
on the close button. Once the forms instance has been closed, it is disposed
and you can no longer use it.
 

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


Back
Top