Is it possible only create form once and active the form second time?

F

foxchan

A Newbie question. Is it possible?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim oNewForm As Form1
'if already create a form for form.text="JustOne" then
JustOne.show()
'else
oNewForm = New Form()
oNewForm.Text = "JustOne"
oNewForm.Show()
end if
End Sub
 
C

Cor

Hi Foxchan,

It is probably possible, however when this is in a program it is a sign of
bad program flow and will led to more bad program design.

The form is not something stand alone, it needs to get or give information,
so when the user enters something it has to give that information to the
program and when the user is able to close the form, that has to be told to
the program (it is easy to prevent closing a from by the user by setting the
controlbox properties to false).

Just my thought,

Cor
 
A

Armin Zingler

foxchan said:
A Newbie question. Is it possible?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim oNewForm As Form1
'if already create a form for form.text="JustOne" then
JustOne.show()
'else
oNewForm = New Form()
oNewForm.Text = "JustOne"
oNewForm.Show()
end if
End Sub

Declare oNewForm as a Field (=at class level). Next time, check whether
oNewForm is Nothing. If it isn't, activate the Form, otherwise create a new
one. Handle the Form's Closed event where you set oNewForm = Nothing.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
F

foxchan

Thank cor, Actually I want to create MDI form.
I saw an example from Book.
the MDiParent
Private Sub mniFileNew_Click(Byval sender as System.object,Byval e as
System.EventArgs) Handle mniFileNew.Click
Dim frmNew as New frmMDIChild()
frmNew.MdiParent = Me
FrmNew.Text = "Son Form"
FrmNew.Show()
End Sub
When I click this button, It create one Child Form. then I click the button
again it create another Form.
I just wonder is it possible it just create ONE child form and avoid to
recreate another form.
 
C

Cor

Hi Foxchan,

When it is about a MDI than put that in the subject,
Some of the regulars are specialized in that (not me).

What I said before is in my opinion not completly true for a MDI form.

However although I know almost nothing from an MDI, I know that a MDI form
is always a child and has a parent, so I would look at that, you saw I
putted MDI in the subject so when you are lucky Armin sees that and helps
you.

Cor
 
E

EricJ

have a look in the mdiParentForm.MdiChildren.Length
You will find most of the things you are looking for in
mdiParentForm.MdiChildren like search if a form exists ...

hope it helps

eric
 

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