John Moore
John Moore

Reputation: 519

Open New Form on button click, Close exisiting Form, VS2010

Sorry for asking a really dumb question. I've been a vb6 programmer for years and I am just developing my first application in VS2010.

I'm trying to open a new form on a button click and close the current form.

In VB6 I would have used.

Me.Close Form.Show vbmodal

I've googled for a solution and it tells me the code is basically the same

form.show() me.close However, when I click the button the program closes. If I take away me.close, the form shows.

I'm really confused.

Thanks

John

Upvotes: 3

Views: 68903

Answers (3)

Pacifique Bananeza
Pacifique Bananeza

Reputation: 1

    Dim f As New Form1
    f.Show()

Checked!! as you see I declare f as new Form1, here you have to change with your form name under form properties then the next line is to show the copy of f!

Upvotes: 0

kaushik0033
kaushik0033

Reputation: 677

Try with Me.Hide() in place of Me.Close().

Upvotes: 2

Steve
Steve

Reputation: 216293

If the form that you are closing is the one that starts your application ('startup form'), then your application ends.

Try with

Me.Hide()
form.Show()

But you could also change the Property Shutdown mode for the project.
On the Applications Tab set the Shutdown mode to When the last form closes.
Of course, in this case, the order of the commands should be

form.Show()
Me.Close()

Upvotes: 9

Related Questions