Cant intercommunicate between managed classes
-
I can figure out how to do this with normal classes, but with managed forms, I am totally stumped. All I wanna do is communicate between forms. In this example, I wanna make the current form invisible, and make the other form visible, but after 2 weeks, still can't do it. I've had responses from people on it, but they only work for unmanaged classes, not these strange manged type things. The problem is trying to get the second form to point to the first one when it hasn't yet been fully defined. Get errors such as error C2512: 'datapassing::Form1' : no appropriate default constructor available Please someone help me, Using Microsoft Visual C++.NET V2003 I could manage forms untill .NET decided to manage them for me!! **Form1.h**
#pragma once #include "Form2.h" namespace datapassing { public __gc class Form1 : public System::Windows::Forms::Form { public: Form2 *pFrm2; public: Form1(void) { InitializeComponent(); pFrm2 = new Form2; } private: System::Void button1_Click(System::Object * sender, System::EventArgs * e) { pFrm2->Visible = true; this->Visible = false; } }; }
**Form2.h**#pragma once namespace datapassing { public __gc class Form1; public __gc class Form2 : public System::Windows::Forms::Form { public: Form1 *pFrm1; public: Form2(void) { InitializeComponent(); pFrm1 = new Form1; } private: System::Void button1_Click(System::Object * sender, System::EventArgs * e) { pFrm1->Visible = true; this->Visible = false; } }; }
-
I can figure out how to do this with normal classes, but with managed forms, I am totally stumped. All I wanna do is communicate between forms. In this example, I wanna make the current form invisible, and make the other form visible, but after 2 weeks, still can't do it. I've had responses from people on it, but they only work for unmanaged classes, not these strange manged type things. The problem is trying to get the second form to point to the first one when it hasn't yet been fully defined. Get errors such as error C2512: 'datapassing::Form1' : no appropriate default constructor available Please someone help me, Using Microsoft Visual C++.NET V2003 I could manage forms untill .NET decided to manage them for me!! **Form1.h**
#pragma once #include "Form2.h" namespace datapassing { public __gc class Form1 : public System::Windows::Forms::Form { public: Form2 *pFrm2; public: Form1(void) { InitializeComponent(); pFrm2 = new Form2; } private: System::Void button1_Click(System::Object * sender, System::EventArgs * e) { pFrm2->Visible = true; this->Visible = false; } }; }
**Form2.h**#pragma once namespace datapassing { public __gc class Form1; public __gc class Form2 : public System::Windows::Forms::Form { public: Form1 *pFrm1; public: Form2(void) { InitializeComponent(); pFrm1 = new Form1; } private: System::Void button1_Click(System::Object * sender, System::EventArgs * e) { pFrm1->Visible = true; this->Visible = false; } }; }
Hai U can done it very simply. Don't include or declare Form1 in Form2 . It will produce circular referencing. change ur code like this **Form1.h** #pragma once #include "Form2.h" namespace datapassing { public __gc class Form1 : public System::Windows::Forms::Form { public: Form2 *pFrm2; public: Form1(void) { InitializeComponent(); pFrm2 = new Form2; pFrm2->Owner=this; } private: System::Void button1_Click(System::Object * sender, System::EventArgs * e) { pFrm2->Visible = true; this->Visible = false; } }; } **Form2.h** #pragma once namespace datapassing { public __gc class Form2 : public System::Windows::Forms::Form { public: public: Form2(void) { InitializeComponent(); } private: System::Void button1_Click(System::Object * sender, System::EventArgs * e) { this->Owner->Visible = true; this->Visible = false; } }; } By Anish
-
Hai U can done it very simply. Don't include or declare Form1 in Form2 . It will produce circular referencing. change ur code like this **Form1.h** #pragma once #include "Form2.h" namespace datapassing { public __gc class Form1 : public System::Windows::Forms::Form { public: Form2 *pFrm2; public: Form1(void) { InitializeComponent(); pFrm2 = new Form2; pFrm2->Owner=this; } private: System::Void button1_Click(System::Object * sender, System::EventArgs * e) { pFrm2->Visible = true; this->Visible = false; } }; } **Form2.h** #pragma once namespace datapassing { public __gc class Form2 : public System::Windows::Forms::Form { public: public: Form2(void) { InitializeComponent(); } private: System::Void button1_Click(System::Object * sender, System::EventArgs * e) { this->Owner->Visible = true; this->Visible = false; } }; } By Anish
This is fantastic, thanks, works just fine. One further thing though. I have a text box textBox1 in form 1. I need to update it from form 2, I assumed that if I could make the form visible/invisible, I could also update the text box, so using your code I tried this->Owner->textBox1->Text = "Updated Text"; This doesn't work, as the Owner only seems to be able to see the general form attributes, not the actual components of the form. How therefore do I change things such as text in the text box in form1, dependant upon an action in form2. If anyone can solve this problem for me (Been trying to figure it for 2 weeks now, but no-one is telling), I will consider you a god, and worship you daily. Thanks Ultimate Newbie
-
This is fantastic, thanks, works just fine. One further thing though. I have a text box textBox1 in form 1. I need to update it from form 2, I assumed that if I could make the form visible/invisible, I could also update the text box, so using your code I tried this->Owner->textBox1->Text = "Updated Text"; This doesn't work, as the Owner only seems to be able to see the general form attributes, not the actual components of the form. How therefore do I change things such as text in the text box in form1, dependant upon an action in form2. If anyone can solve this problem for me (Been trying to figure it for 2 weeks now, but no-one is telling), I will consider you a god, and worship you daily. Thanks Ultimate Newbie
Hai, i dont know the what i am saying is correct. but ur probelm can be solved in this way. But this is not recommended if u have heavy updation in ur Form1 class. One more reason for my qucik response is that next four days will not here. simply pass a reference of ur textbox to the Form2 class ie Create a TExtbox object in ur Form2 class; TextBox* t1; Passes the reference of original one to this value in Constructor frm2->t1=this->textBox1; Now u can update the text in Button click as this->tt->Text="Updated Text"; By Anish If u find a good solution plz post it here