Moving Between Forms

  • Thread starter Thread starter Corey
  • Start date Start date
C

Corey

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
 
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?
 
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
 
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!
 
Back
Top