How to show second form in a windows app

G

Guest

Hey guys,
I have multiple forms in my windows app, and in my startup form i am doing
the following in order to navigate to a different form:

Dim myform as New frmsecondform
frmsecondform=mynamespace.originalsecondformname
myform.show

As soon as I try to run the application, the main form shows up, I try to
click the button to navigate to a different form but it just closes., without
navigating. any ideas? Thanks in advance

~Ken
 
C

Cor Ligthert

Ken,

I cannot see from the code you show now what is happening. I cannot see
where you have placed it, what is very important.

However your code is strange
Dim myform as New frmsecondform
Instance a complete myform from the class frmsecondform
frmsecondform=mynamespace.originalsecondformname
frmsecondform is a class(type) what is orinalsecondformname as well.
So I don't know what you want to do.
myform.show

Withouth the second line would this show the new instance of frmsecondform

I hope this helps?

Cor
 
C

Chris Dunaway

Which form closes? The second one? Or does the app just close?
Dim myform as New frmsecondform
frmsecondform=mynamespace.originalsecondformname
myform.show

I'm sure what you're attempting to accomplish with the second line
above but if you leave it out and just call myform.Show, it should
work. Can you provide more information?

Chris
 
G

Guest

I apologize for the confusion, this is the code:

Dim myform as New Form
myform=myappname.originalsecondformname
myform.show

I am placing this code in a button Click Event. Just to make sure, I put
this following code in the second form load event:

MsgBox("hey i am here in the second form")

which is firing as soon as I click the button_Click in the main form.But I
cannot see the form., and everything closes after that(both the main and the
second form).

Thanks once again.

~Ken
 
C

Chad Z. Hower aka Kudzu

"=?Utf-8?B?dHduZXR5MG5lQHlhaG9vLmNvbQ==?="
I apologize for the confusion, this is the code:

Dim myform as New Form
myform=myappname.originalsecondformname
myform.show

I am placing this code in a button Click Event. Just to make sure, I
put this following code in the second form load event:

MsgBox("hey i am here in the second form")

which is firing as soon as I click the button_Click in the main form.But
I cannot see the form., and everything closes after that(both the main
and the second form).

Is this the only code you have? Do you have anything after the Show method?
Is the form set to visible?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
 
G

Guest

Dim myform as New frmsecondform
frmsecondform=mynamespace.originalsecondformname
myform.show


Instead of the above try :

Dim myform as New frmsecondform
myform.show

The second line "frmsecondform=mynamespace.originalsecondformname" is
unnecessary and I suspect it is the reason your form does not show.
 
G

Guest

ok., this is the original code(i am copy/pasting it)

what i am doing is., i am navigating to a different form based on the
formname stored in a variable called strFormNameHolder., but it doesnt work(I
cant see the second form).

Dim myForm As Type = Type.GetType(strFormNameHolder)
Dim myFormObject As Object =
Activator.CreateInstance(Type.GetType(strFormNameHolder))
Dim frmNavigateto As New Form
frmNavigateto = DirectCast(myFormObject, Form)
frmNavigateto.Show()
frmNavigateto.Visible=true
Me.Close
Me.Dispose

This code is in a button_click sub, as soon as the event is fired., the
application seems to run and immediately close.


Thanks again.


~Ken
 
C

Chris Dunaway

Dim myForm As Type = Type.GetType(strFormNameHolder)
Dim myFormObject As Object =
Activator.CreateInstance(Type.GetType(strFormNameHolder))
Dim frmNavigateto As New Form

You don't need the New keyword above, it creates a new form and you
have already done that by calling activator.createinstance.
frmNavigateto = DirectCast(myFormObject, Form)
frmNavigateto.Show()
frmNavigateto.Visible=true
Me.Close
Me.Dispose

I presume that Me refers to the main form which is the startup object
of your project? When you close this form, it closes the application.
If you wish to hide the main form while the second form is visible,
call its Hide method instead of Close and don't dispose the form
either.
 
G

Guest

No. You do not need to use mdi forms to do what you are trying to accomplish.

Have you had any success with the forms yet?
 

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