CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2012
    Posts
    9

    Exclamation switch between forms

    hi, I switch from Form1 to Form2 by the following code:

    in Form1:

    #pragma once
    #include "Form2.h"
    .
    .

    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    Form2^ x = gcnew Form2();
    x->ShowDialog();
    this->Hide();

    in Form2:

    pragma once
    #include "Form1.h"
    .
    .
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    Form1^ y = gcnew Form1();
    y->ShowDialog();
    this->Hide();

    but when I run it , it gives me error. how I can solve it??

    thanks in advance.

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: switch between forms

    Please note that your code is C++/CLI, so you've posted in the wrong forum section. The right one is this: http://forums.codeguru.com/forumdisp...ed-C-and-C-CLI

    I doubt you could ever get that to compile, so you never were able to run it either. What you have here is the rather common circular inclusion problem, which isn't even specific to C++/CLI. It has been discussed around here quite a bunch of times, but, admittely, finding these discussions would be much easier if the forum search feature would work, what it seems to still not do since the recent forum software update.

    And even if you'd get it to run, this wouldn't do what you seem to expect:

    Code:
    x->ShowDialog();
    this->Hide();
    x-ShowDialog(); won't return before the user dismisses x, so this does not have the effect that the user doesn't see this while x is open. There have been quite a bunch of discussions about this scenario in the C++/CLI section I linked to above, but again here applies that thing about the forum search...

    Finally, please use code tags when posting code. You can see part of the effect that has above.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured