469,649 Members | 1,171 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,649 developers. It's quick & easy.

Simple - Show Form

dp
I am new to VB.NET and I have a simple question. How do I show a form
from a command button click event? The code I have below is not
working. I am trying to show the form frmAgent. What am I missing?

Private Sub cmdNewAgent_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdNewAgent.Click
Dim frm1 As New frmAgent()
frm1.Show()
Me.Hide()
End Sub
Jul 19 '05 #1
3 6384
What's happening? There's nothing wrong with that code as it appears.

If you put a breakpoint on the click event and hit the button, are you
definitely hitting it in the code window?
"dp" <da**@solidservices.net> wrote in message
news:d1**************************@posting.google.c om...
I am new to VB.NET and I have a simple question. How do I show a form
from a command button click event? The code I have below is not
working. I am trying to show the form frmAgent. What am I missing?

Private Sub cmdNewAgent_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdNewAgent.Click
Dim frm1 As New frmAgent()
frm1.Show()
Me.Hide()
End Sub

Jul 19 '05 #2
Rob:

Are you sure about that? Every time you fire a new form you need to send
Application.Run(frm1);?

Why would that cause Form2 not to show?
"Rob Windsor" <rw******@NO.MORE.SPAM.bigfoot.com> wrote in message
news:uX*************@TK2MSFTNGP11.phx.gbl...

You need to change "frm1.Show()" to "Application.Run(frm1)". If you just use the show method the form will close when the variable frm1 goes out of
scope.

--
Rob Windsor
G6 Consulting
Toronto, Canada

"dp" <da**@solidservices.net> wrote in message
news:d1**************************@posting.google.c om...
I am new to VB.NET and I have a simple question. How do I show a form
from a command button click event? The code I have below is not
working. I am trying to show the form frmAgent. What am I missing?

Private Sub cmdNewAgent_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdNewAgent.Click
Dim frm1 As New frmAgent()
frm1.Show()
Me.Hide()
End Sub


Jul 19 '05 #3
If you want to show a non-modal form you need to use Application.Run(<form
variable>) to set up a message loop on the form's thread. If you don't do
this (i.e. you use the Show method) the form closes when the variable that
refrences it goes out of scope. In the previous message that was when the
event handling subroutine ended. Note that this is not required for modal
forms, the ShowDialog method does this for you.

Rob

"William Ryan" <do********@comcast.nospam.net> wrote in message
news:OJ*************@TK2MSFTNGP10.phx.gbl...
Rob:

Are you sure about that? Every time you fire a new form you need to send
Application.Run(frm1);?

Why would that cause Form2 not to show?
"Rob Windsor" <rw******@NO.MORE.SPAM.bigfoot.com> wrote in message
news:uX*************@TK2MSFTNGP11.phx.gbl...

You need to change "frm1.Show()" to "Application.Run(frm1)". If you just

use
the show method the form will close when the variable frm1 goes out of
scope.

--
Rob Windsor
G6 Consulting
Toronto, Canada

"dp" <da**@solidservices.net> wrote in message
news:d1**************************@posting.google.c om...
I am new to VB.NET and I have a simple question. How do I show a form
from a command button click event? The code I have below is not
working. I am trying to show the form frmAgent. What am I missing?

Private Sub cmdNewAgent_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdNewAgent.Click
Dim frm1 As New frmAgent()
frm1.Show()
Me.Hide()
End Sub



Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Tal Sharfi | last post: by
3 posts views Thread by dp | last post: by
4 posts views Thread by Duncan | last post: by
1 post views Thread by www.web20developers.com | last post: by
3 posts views Thread by deejayquai | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.