Circular Form Reference
-
Hey, I am trying to open form2 from form1. Then open a new form1 when form2 is closed. But adding the #include "Form1.h" header to form2.h is causing errors (undeclared identifier). I added these inclusion guards and tried using forward declaration. EIther that didn't work or I used it wrong, not sure I followed the correct syntax since all of the code is in the header files - the automatically generated code for Forms and controls. /*Form1.h*/ #pragma once #ifndef First #define First #include "Form2.h" private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Form2 ^ frm = gcnew Form2; frm->Show(); this->Close(); } #endif /*Form2.h*/ #pragma once #ifndef Second #define Second #include "Form1.h" private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Form1 ^ frm = gcnew Form1; frm->Show(); this->Close(); } #endif
-
Hey, I am trying to open form2 from form1. Then open a new form1 when form2 is closed. But adding the #include "Form1.h" header to form2.h is causing errors (undeclared identifier). I added these inclusion guards and tried using forward declaration. EIther that didn't work or I used it wrong, not sure I followed the correct syntax since all of the code is in the header files - the automatically generated code for Forms and controls. /*Form1.h*/ #pragma once #ifndef First #define First #include "Form2.h" private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Form2 ^ frm = gcnew Form2; frm->Show(); this->Close(); } #endif /*Form2.h*/ #pragma once #ifndef Second #define Second #include "Form1.h" private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Form1 ^ frm = gcnew Form1; frm->Show(); this->Close(); } #endif
Your post is wrong on so many levels it's difficult to know where to start. First, it is obvious you are a beginner. I don't know of any authoritative source for this but common sense tells me that Managed C++ development is not appropriate for beginners. Beginners probably need to learn C/C++ basics and consider CLI an advanced topic. Next, as a user, if an application is popping up windows all the time I am closing it and uninstalling it. There is absolutely no need to open up new top level windows just to display a different view. Tabs are also grossly abused, from an MDI or Configuration perspective they make sense, but not as a Primary UI design. Another thing, if you insist on this insanely poor path, the fundamental solution to a circular dependency problem is to introduce a third item to the picture and define the relationships such that the original two items are unrelated.
item one item two
\ /
\ /
\ /
new itemOne other thing, you might want to start learning what Software Design Patterns are. Good luck :beer:
modified on Tuesday, March 24, 2009 1:01 PM
-
Your post is wrong on so many levels it's difficult to know where to start. First, it is obvious you are a beginner. I don't know of any authoritative source for this but common sense tells me that Managed C++ development is not appropriate for beginners. Beginners probably need to learn C/C++ basics and consider CLI an advanced topic. Next, as a user, if an application is popping up windows all the time I am closing it and uninstalling it. There is absolutely no need to open up new top level windows just to display a different view. Tabs are also grossly abused, from an MDI or Configuration perspective they make sense, but not as a Primary UI design. Another thing, if you insist on this insanely poor path, the fundamental solution to a circular dependency problem is to introduce a third item to the picture and define the relationships such that the original two items are unrelated.
item one item two
\ /
\ /
\ /
new itemOne other thing, you might want to start learning what Software Design Patterns are. Good luck :beer:
modified on Tuesday, March 24, 2009 1:01 PM
-
Wow, talk about confused. For someone who doesn't know the answer you sure have a lot to say. Clearly, you misunderstand an attempt to simplify an example. As such you should consider not "answering" (loosely used, in your case) to people's posts.
thenutz72 wrote:
Wow, talk about confused.
Ok, let's talk about that. What are you confused about?
thenutz72 wrote:
For someone who doesn't know the answer
Um, "the answer"? Really, there is only one way to solve your problem, interesting. What part of my post does not qualify as an answer?
thenutz72 wrote:
you should consider not "answering"
First lets get one thing clear. So far there is not one thing you have said that I would consider let alone that suggestion. By the way if you continue to attempt to berate my reply it will end with me ripping your virtual head off and shoving it down your ignorant throat.
-
thenutz72 wrote:
Wow, talk about confused.
Ok, let's talk about that. What are you confused about?
thenutz72 wrote:
For someone who doesn't know the answer
Um, "the answer"? Really, there is only one way to solve your problem, interesting. What part of my post does not qualify as an answer?
thenutz72 wrote:
you should consider not "answering"
First lets get one thing clear. So far there is not one thing you have said that I would consider let alone that suggestion. By the way if you continue to attempt to berate my reply it will end with me ripping your virtual head off and shoving it down your ignorant throat.
-
Hey, I am trying to open form2 from form1. Then open a new form1 when form2 is closed. But adding the #include "Form1.h" header to form2.h is causing errors (undeclared identifier). I added these inclusion guards and tried using forward declaration. EIther that didn't work or I used it wrong, not sure I followed the correct syntax since all of the code is in the header files - the automatically generated code for Forms and controls. /*Form1.h*/ #pragma once #ifndef First #define First #include "Form2.h" private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Form2 ^ frm = gcnew Form2; frm->Show(); this->Close(); } #endif /*Form2.h*/ #pragma once #ifndef Second #define Second #include "Form1.h" private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Form1 ^ frm = gcnew Form1; frm->Show(); this->Close(); } #endif
if you are creating a windows form application under CLR category then in Form1.h your code must be like this:
#pragma once
#include "Form2.h"namespace CircularForm {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
.
.
.private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Form2^ f2 = gcnew Form2();
f2->Show();
this->Close();
}but when the form1 is closed the managed memory of form2 will be released. the whole program will be ended. there is 2 way to do this: 1. don't close the form1, just hide form1 and when form2 is closed show it(form1) again. 2. add a new class (Form3) containing two objects (Form1 f1, Form2 f2). set it as startup form and control the f1,f2
sometimes 0 can be 1