Reference a hidden form without using Me keyword

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NetMasker

    Reference a hidden form without using Me keyword

    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.



  • Sarika

    #2
    RE: Reference a hidden form without using Me keyword

    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.DefInsta nce.Hide()

    'Show the hidden instance
    myform.DefInsta nce.Show()
    ///

    HTH

    Comment

    • NetMasker

      #3
      Re: Reference a hidden form without using Me keyword

      Sorry for the misunderstandin g, 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 "DefInstanc e" is ? It is not an accepted keyword so what should I
      put there ??

      Thanks again.



      "Sarika" <Sarika@discuss ions.microsoft. com> wrote in message
      news:7AD541B7-1F9A-4B03-BF98-3CA340567846@mi crosoft.com...[color=blue]
      > The code snippet that you have posted will create a new instance of the[/color]
      Form1[color=blue]
      > 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.DefInsta nce.Hide()
      >
      > 'Show the hidden instance
      > myform.DefInsta nce.Show()
      > ///
      >
      > HTH[/color]



      Comment

      • Sarika

        #4
        Re: Reference a hidden form without using Me keyword

        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_vb6FormDefIns tance As Form1
        Private Shared m_InitializingD efInstance As Boolean

        'This property returns an instance of Form1
        Public Shared Property DefInstance() As Form1
        Get
        If m_vb6FormDefIns tance Is Nothing _
        OrElse m_vb6FormDefIns tance.IsDispose d Then
        m_InitializingD efInstance = True
        m_vb6FormDefIns tance = New Form1()
        m_InitializingD efInstance = False
        End If
        DefInstance = m_vb6FormDefIns tance
        End Get
        Set(ByVal Value As Form1)
        m_vb6FormDefIns tance = Value
        End Set
        End Property
        ///

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

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

        Hopefully I answered your qn this time!


        Comment

        • NetMasker

          #5
          Re: Reference a hidden form without using Me keyword

          Complicated but it worked! Thanks

          "Sarika" <Sarika@discuss ions.microsoft. com> wrote in message
          news:ACD465CF-A4C2-43DC-841D-CCBBA6D145F9@mi crosoft.com...[color=blue]
          > 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_vb6FormDefIns tance As Form1
          > Private Shared m_InitializingD efInstance As Boolean
          >
          > 'This property returns an instance of Form1
          > Public Shared Property DefInstance() As Form1
          > Get
          > If m_vb6FormDefIns tance Is Nothing _
          > OrElse m_vb6FormDefIns tance.IsDispose d Then
          > m_InitializingD efInstance = True
          > m_vb6FormDefIns tance = New Form1()
          > m_InitializingD efInstance = False
          > End If
          > DefInstance = m_vb6FormDefIns tance
          > End Get
          > Set(ByVal Value As Form1)
          > m_vb6FormDefIns tance = Value
          > End Set
          > End Property
          > ///
          >
          > To show Form1 you need to add the statement
          > \\\
          > Form1.DefInstan ce.Show()
          > ///
          >
          > I am sure there could be simpler methods to achieving this.
          >
          > Hopefully I answered your qn this time!
          >
          >[/color]


          Comment

          Working...