Moving Between Forms

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

    #1

    Moving Between Forms

    Dear All,

    I know there's a simple solution to what I want to do, but for the life of
    me I can't figure it out. I think it's because I've been corrupted by too
    long with VB6..... :)

    Any way this is what I want to achieve.

    FormA has a button on it that creates an instance of FormB. It then shows
    FormB and Hides itself.
    FormB has a button to take the user back to FormA so that they can exit if
    they wish. Closing FormB should also bring FormA back.

    Any ideas?

    With thanks.

    -Corey


  • GMorris

    #2
    Re: Moving Between Forms

    I, too, was "corrupted" by the VB6 environment, and I had a little
    moment myself trying to do this same thing. Still not sure if there is
    a "right" way to acheive it, but the way I finally got it to work was
    to add a Form parameter to the constructor of the second form,
    (I guess your FormB) and then passed "this" to it when I created
    the instance of FormB from FormA. I also created a Form variable
    in FormB to be assigned the passed instance of FormA. The reason
    I did it that way is that I could not figure out any other way to get
    back to FormA once it was hidden. Now, I suppose one could
    just call FormB and destroy FormA, then re-create a new FormA
    when closing FormB, but that's not the same as just hiding FormA
    and then showing it again. I'm interested in finding out that there is
    another, better or more correct way to do this, as the way I describe
    works, but when I close B and show A again, it comes up behind
    other open windows rather than on top. Anyone?

    "Corey" <Corey@On.The.N et> wrote in message
    news:u7qG33jtDH A.2360@TK2MSFTN GP09.phx.gbl...[color=blue]
    > Dear All,
    >
    > I know there's a simple solution to what I want to do, but for the life of
    > me I can't figure it out. I think it's because I've been corrupted by too
    > long with VB6..... :)
    >
    > Any way this is what I want to achieve.
    >
    > FormA has a button on it that creates an instance of FormB. It then shows
    > FormB and Hides itself.
    > FormB has a button to take the user back to FormA so that they can exit if
    > they wish. Closing FormB should also bring FormA back.
    >
    > Any ideas?
    >
    > With thanks.
    >
    > -Corey
    >
    >[/color]


    Comment

    • Corey

      #3
      Re: Moving Between Forms

      GMorris,

      The way you describe works really well. Instead of using the constructor I
      used a seperate method. The only reason was for personal preference. I
      prefer not to overload constructors when I don't have to.

      In answer to your question though I believe the property called "toplevel"
      of a form object is what you're looking for. In this way, as I understand
      the documentation, the form will re-appear on top of all the other windows.

      Many thanks for your help.

      -Corey


      "GMorris" <gwmorris1@hotp op.com> wrote in message
      news:u$lD09ttDH A.1884@TK2MSFTN GP10.phx.gbl...[color=blue]
      > I, too, was "corrupted" by the VB6 environment, and I had a little
      > moment myself trying to do this same thing. Still not sure if there is
      > a "right" way to acheive it, but the way I finally got it to work was
      > to add a Form parameter to the constructor of the second form,
      > (I guess your FormB) and then passed "this" to it when I created
      > the instance of FormB from FormA. I also created a Form variable
      > in FormB to be assigned the passed instance of FormA. The reason
      > I did it that way is that I could not figure out any other way to get
      > back to FormA once it was hidden. Now, I suppose one could
      > just call FormB and destroy FormA, then re-create a new FormA
      > when closing FormB, but that's not the same as just hiding FormA
      > and then showing it again. I'm interested in finding out that there is
      > another, better or more correct way to do this, as the way I describe
      > works, but when I close B and show A again, it comes up behind
      > other open windows rather than on top. Anyone?
      >
      > "Corey" <Corey@On.The.N et> wrote in message
      > news:u7qG33jtDH A.2360@TK2MSFTN GP09.phx.gbl...[color=green]
      > > Dear All,
      > >
      > > I know there's a simple solution to what I want to do, but for the life[/color][/color]
      of[color=blue][color=green]
      > > me I can't figure it out. I think it's because I've been corrupted by[/color][/color]
      too[color=blue][color=green]
      > > long with VB6..... :)
      > >
      > > Any way this is what I want to achieve.
      > >
      > > FormA has a button on it that creates an instance of FormB. It then[/color][/color]
      shows[color=blue][color=green]
      > > FormB and Hides itself.
      > > FormB has a button to take the user back to FormA so that they can exit[/color][/color]
      if[color=blue][color=green]
      > > they wish. Closing FormB should also bring FormA back.
      > >
      > > Any ideas?
      > >
      > > With thanks.
      > >
      > > -Corey
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • GMorris

        #4
        Re: Moving Between Forms

        Thanks, I figured it out pretty soon after I wrote that, just did a
        form.Activate
        right after the form.Show call. Worked like a charm. I have seen this
        question
        in several places already, and even though I have yet to need this
        functionality,
        I just had to know how to do it, at least one way that works. Things like
        this
        will drive you crazy until you figure them out!

        "Corey" <Corey@On.The.N et> wrote in message
        news:OZJ4AyMuDH A.2316@TK2MSFTN GP10.phx.gbl...[color=blue]
        > GMorris,
        >
        > The way you describe works really well. Instead of using the constructor I
        > used a seperate method. The only reason was for personal preference. I
        > prefer not to overload constructors when I don't have to.
        >
        > In answer to your question though I believe the property called "toplevel"
        > of a form object is what you're looking for. In this way, as I understand
        > the documentation, the form will re-appear on top of all the other[/color]
        windows.[color=blue]
        >
        > Many thanks for your help.
        >
        > -Corey
        >
        >
        > "GMorris" <gwmorris1@hotp op.com> wrote in message
        > news:u$lD09ttDH A.1884@TK2MSFTN GP10.phx.gbl...[color=green]
        > > I, too, was "corrupted" by the VB6 environment, and I had a little
        > > moment myself trying to do this same thing. Still not sure if there is
        > > a "right" way to acheive it, but the way I finally got it to work was
        > > to add a Form parameter to the constructor of the second form,
        > > (I guess your FormB) and then passed "this" to it when I created
        > > the instance of FormB from FormA. I also created a Form variable
        > > in FormB to be assigned the passed instance of FormA. The reason
        > > I did it that way is that I could not figure out any other way to get
        > > back to FormA once it was hidden. Now, I suppose one could
        > > just call FormB and destroy FormA, then re-create a new FormA
        > > when closing FormB, but that's not the same as just hiding FormA
        > > and then showing it again. I'm interested in finding out that there is
        > > another, better or more correct way to do this, as the way I describe
        > > works, but when I close B and show A again, it comes up behind
        > > other open windows rather than on top. Anyone?
        > >
        > > "Corey" <Corey@On.The.N et> wrote in message
        > > news:u7qG33jtDH A.2360@TK2MSFTN GP09.phx.gbl...[color=darkred]
        > > > Dear All,
        > > >
        > > > I know there's a simple solution to what I want to do, but for the[/color][/color][/color]
        life[color=blue]
        > of[color=green][color=darkred]
        > > > me I can't figure it out. I think it's because I've been corrupted by[/color][/color]
        > too[color=green][color=darkred]
        > > > long with VB6..... :)
        > > >
        > > > Any way this is what I want to achieve.
        > > >
        > > > FormA has a button on it that creates an instance of FormB. It then[/color][/color]
        > shows[color=green][color=darkred]
        > > > FormB and Hides itself.
        > > > FormB has a button to take the user back to FormA so that they can[/color][/color][/color]
        exit[color=blue]
        > if[color=green][color=darkred]
        > > > they wish. Closing FormB should also bring FormA back.
        > > >
        > > > Any ideas?
        > > >
        > > > With thanks.
        > > >
        > > > -Corey
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...