Results 1 to 5 of 5

Thread: How do you open another form with out creating another instance

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    BC,Canada
    Posts
    15

    How do you open another form with out creating another instance

    i'm using hide and close events from form. but what i found out is it creates every time another instance
    this is the code i used

    Dim AFormInstance As New form1()
    AFormInstance.Show()
    Me.Hide()

    How to get 1 instance instead of many?

  2. #2
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261
    Declare a class-level variable instead of a procedure-level one.

    Code:
    Public Class MyForm
         Inherits System.Windows.Forms.Form
    
         Public FRM as new Form()
    
         Public Sub ShowFRM()
         
              FRM.Show()
    
         End Sub
    
    End Class
    Something like this should work just fine.

    Originally posted by Edneeis:

    I think you have to track the forms at a module level or pass references of the instances back and forth to the different forms.
    I disagree. Passing references like that would only lead to spaghetti code. It can be done, but your code would be a bit harder to read, and harder to debug if you have a lot of forms.
    Last edited by Hu Flung Dung; Sep 27th, 2002 at 02:35 AM.

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I think you have to track the forms at a module level or pass references of the instances back and forth to the different forms.

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    If you want to pass data back and forth, you will need a reference to do so or another class that acts as an intermediatery (spell) between the two. Edneeis is right.

  5. #5
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261
    Originally posted by hellswraith
    If you want to pass data back and forth, you will need a reference to do so or another class that acts as an intermediatery (spell) between the two. Edneeis is right.
    Hmm. With an application that has a lot of forms, it might get difficult to keep track of all those form references.

    I like the idea of a shared class acting like an intermediatery though. It would help to keep things centralized and simple.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width