Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple forms 1

Status
Not open for further replies.

samsonx

Technical User
May 5, 2003
46
AU
What is the deal with .NET and multiple forms? In VB6 it was so easy.

I have an app with six forms. The problem I am having is killing a form and opening a new one.

I want to be able to click a button and open another form. At the same time, when the new form is opened, the old one must be killed. Hiding the form is not what I want to use.

Any ideas?

 
the first form shoudn't be mdi.
on button
dim f as new form2 (the form you want to open)
s.show
me.close
 
That doesn't seem to work, which is something I tried earlier. As soon as you show the form, no commands after that will be exectued. What do you mean by MDI?

In the case you have shown- if that form closes, so will the entire application. I guess the only other option is to use threading.

Thanks for trying. I'll just have to keep at it.
 
if the form you try to close is the application startup form, than all application will close.
the ideea is that the startup page should be a container for all forms. any other form needs to be open from it. so in order to work what you want, you must do another form and set it as startup, put on it a button to open the first form (the one you want to close)
 
Why bother with all thread when running a form in its own thread is a lot better?

To run a form in it's own thread do this:

1. Import System.Threading

2. Declare all your new Forms and the thread in a module module, e.g

Public objForm1 as new Form1
Public objForm2 as new Form2
Public objForm3 as new Form3
Public objForm4 as new Form4
Public objForm5 as new Form5
Public ObjForm6 as new Form6
Public th1 as threading.thread

3. Make a sub procedure to start a Form, e.g

Private sub StartForm2()
Try
me.close()
Catch ex as ThreadAbortException
'do nothing
End Try
End Sub


4. In the button_click method for the button to open the form, do this:

th1 = new thread(AddressOf StartForm2)
th1.Priority=Priority.BelowNormal
th1.Start


That should solve your problem.

 
Exactly what I was looking for. Thanks! A star goes to You!
 
Whoops...

should read:


Private sub StartForm2()
Try
me.close()
objForm.ShowDialog()
Catch ex as ThreadAbortException
'do nothing
End Try
End Sub
 
Shouldn't it be Imports System.Threading?

I'm getting an error that says that priority is not declare for the line where it says:

th1.Priority=Priority.BelowNormal




 
Yes, my mistake.

Here's once again, with a little more detail.

In this example, there is two Forms called Form1 and Form2 and a module called Module1.

Module1 should have the following variables declared:

Public objForm1 as new Form1
Public objForm2 as new Form2
Public th1 as System.Threading.Thread

Form1 should have a button on it. The form should have:
Imports System.Threading

Write a sub procedure to read:

Private sub StartForm2()
Try
me.close()
objForm2.ShowDialog()
Catch ex as ThreadAbortException
'do nothing
End Try

There should be a button click method for a button which says:

th1 = new thread(AddressOf StartForm2)
th1.priority = ThreadPriority.BelowNormal
th1.start


Do the same for the Form2, except you will have a procedure which called StartForm1.

When you are writing code, follow the suggestion that the code gives, and you should be right. Because I am not on a Windows Machine, I cannot test it but I am sure this works.

Post back if you still have troubles.
 
why not put this in the button click event

me.close

and this in the forms close event

dim f as form
f.show


Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top