Simple - Show Form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dp

    #1

    Simple - Show Form

    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_Cli ck(ByVal sender As System.Object, ByVal e
    As System.EventArg s) Handles cmdNewAgent.Cli ck
    Dim frm1 As New frmAgent()
    frm1.Show()
    Me.Hide()
    End Sub
  • William Ryan

    #2
    Re: Simple - Show Form

    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" <danp@solidserv ices.net> wrote in message
    news:d1749737.0 309020634.78c22 b07@posting.goo gle.com...[color=blue]
    > 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_Cli ck(ByVal sender As System.Object, ByVal e
    > As System.EventArg s) Handles cmdNewAgent.Cli ck
    > Dim frm1 As New frmAgent()
    > frm1.Show()
    > Me.Hide()
    > End Sub[/color]


    Comment

    • William Ryan

      #3
      Re: Simple - Show Form

      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" <rwindsor@NO.MO RE.SPAM.bigfoot .com> wrote in message
      news:uXJn8EWcDH A.356@TK2MSFTNG P11.phx.gbl...[color=blue]
      >
      > You need to change "frm1.Show( )" to "Application.Ru n(frm1)". If you just[/color]
      use[color=blue]
      > the show method the form will close when the variable frm1 goes out of
      > scope.
      >
      > --
      > Rob Windsor
      > G6 Consulting
      > Toronto, Canada
      >
      > "dp" <danp@solidserv ices.net> wrote in message
      > news:d1749737.0 309020634.78c22 b07@posting.goo gle.com...[color=green]
      > > 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_Cli ck(ByVal sender As System.Object, ByVal e
      > > As System.EventArg s) Handles cmdNewAgent.Cli ck
      > > Dim frm1 As New frmAgent()
      > > frm1.Show()
      > > Me.Hide()
      > > End Sub[/color]
      >
      >[/color]


      Comment

      • Rob Windsor

        #4
        Re: Simple - Show Form

        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" <dotnetguru@com cast.nospam.net > wrote in message
        news:OJnsNYWcDH A.748@TK2MSFTNG P10.phx.gbl...[color=blue]
        > 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" <rwindsor@NO.MO RE.SPAM.bigfoot .com> wrote in message
        > news:uXJn8EWcDH A.356@TK2MSFTNG P11.phx.gbl...[color=green]
        > >
        > > You need to change "frm1.Show( )" to "Application.Ru n(frm1)". If you just[/color]
        > use[color=green]
        > > the show method the form will close when the variable frm1 goes out of
        > > scope.
        > >
        > > --
        > > Rob Windsor
        > > G6 Consulting
        > > Toronto, Canada
        > >
        > > "dp" <danp@solidserv ices.net> wrote in message
        > > news:d1749737.0 309020634.78c22 b07@posting.goo gle.com...[color=darkred]
        > > > 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_Cli ck(ByVal sender As System.Object, ByVal e
        > > > As System.EventArg s) Handles cmdNewAgent.Cli ck
        > > > Dim frm1 As New frmAgent()
        > > > frm1.Show()
        > > > Me.Hide()
        > > > End Sub[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...