|
-
Sep 27th, 2002, 01:13 AM
#1
Thread Starter
New Member
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?
-
Sep 27th, 2002, 02:29 AM
#2
Hyperactive Member
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.
-
Sep 27th, 2002, 02:30 AM
#3
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.
-
Sep 27th, 2002, 10:46 AM
#4
PowerPoster
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.
-
Sep 27th, 2002, 11:00 AM
#5
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|