loading forms

  • Thread starter Thread starter Snuyt
  • Start date Start date
S

Snuyt

Hallo,

I have 3 forms : main, form1 and form2

I can open form1 and form2 from main by clicking a button in main.
I can open form2 form form1 by clicking a button in form1.
I can open form1 from form2 by clicking a button in form2.

However, when I open form1 and form2 from main, and then open form1 from
form2, then I get 2 form1's. This is logical because I made new objects.
But how can I prevent this? Which code should I use for loading forms,
and if they already exist, just focussing on that form?

code in the buttons:

Private Sub button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles button.Click
Dim f As form1 'the form to open
f=new form1()
f.Show()
End Sub

Thanks,
Snuyt
 
Hi Snuyt,

I made once this sample as an other approach than normaly is taken,

Maybe you can use it?

Cor

\\\form1
Private WithEvents frm3 As New Form3
Private WithEvents frm2 As New Form2
Private Sub frm2_VisibleChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles frm2.VisibleChanged
If frm2.inputfield <> "" Then
Me.Show()
Me.Label1.Text = frm2.inputfield
frm2.Dispose()
End If
End Sub
Private Sub frm3_VisibleChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles frm3.VisibleChanged
If frm3.inputfield <> "" Then
Me.Show()
Me.Label1.Text = frm3.inputfield
frm3.Dispose()
End If
End Sub

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
frm3.Show()
frm3.TopLevel = True
frm2.Show()
frm2.TopLevel = True
End Sub
///
\\\form2 and 3 the same
Public inputfield As String
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

inputfield = "sometext"
Me.Hide()
End Sub
///
 
Ken said:


Thanks, that was perfect !

Now I only have one problem: If the form is closed, then it is also
disposed. So if I try to reshow that object, I get an error. How do I
make, that instead of closing (and disposing) the form, it is simply
hidden. (closing the form = clicking the closing cross in the
rightuppercorner of the form).

Snuyt
 
Snuyt said:
Thanks, that was perfect !

Now I only have one problem: If the form is closed, then it is also
disposed. So if I try to reshow that object, I get an error. How do I
make, that instead of closing (and disposing) the form, it is simply
hidden. (closing the form = clicking the closing cross in the
rightuppercorner of the form).

Snuyt

Ok, I've found it, just in the windows generated code, changing the code
for disposing did the job.

thanks,

Snuyt
 
Back
Top