Reference a hidden form without using Me keyword

N

NetMasker

How can I reference a form (from withing a module for example) and make it
visible without using the keyword "Me" ?

I tried with the following code but nothing happened:

Public myform As Form1
myform = New Form1
myform.Show()

Of course my application defines a form called Form1.

Thanks in advance.
 
G

Guest

The code snippet that you have posted will create a new instance of the Form1
and display it.

By what I understand from yur post is that, you already have an instance
created and you have hidden that instance and now you want to display this
hidden instance, right?

\\\

Public myform As Form1
myform = New Form1
'Hide the instance
myform.DefInstance.Hide()

'Show the hidden instance
myform.DefInstance.Show()
///

HTH
 
N

NetMasker

Sorry for the misunderstanding, it's my fault.

I do not want to create a new instance of the Form1. I just want to be able
to show and hide the "Main and Only form" that I use with code in a module
(or inside
the class Form1 but without using the "Me" keyword).

Also, what "DefInstance" is ? It is not an accepted keyword so what should I
put there ??

Thanks again.
 
G

Guest

Apologies for my uncommented code. This is one way you could reference an
instance of your Form.

\\\
'Add this code to the Form1 class
Private Shared m_vb6FormDefInstance As Form1
Private Shared m_InitializingDefInstance As Boolean

'This property returns an instance of Form1
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
///

To show Form1 you need to add the statement
\\\
Form1.DefInstance.Show()
///

I am sure there could be simpler methods to achieving this.

Hopefully I answered your qn this time!
 

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

Top