[C++ CLI] Include form1 in form2 and form2 in form1 at same time

Hello, again i have small problem, when i want open another form with button,works excelent, but when i want hide first form, it works, but when i want after form2 close show form1 again, then i need include form1 in form2, but when i include, i have problems like "form is undeclared".

Example
1
2
3
4
5
6
7
8
9
10
11
//Form1 Loginscreen
#include "HlavneMenu.h"
.
.
.
HlavneMenu^ hlavnemenu = gcnew HlavneMenu();
						hlavnemenu->UserId = reader->GetString(0);
						hlavnemenu->Show();
.
.
.


this works when i dont include this form in hlavnemenu form. when i do this->
1
2
3
4
//Form2 HlavneMenu(headmenu)

#include "LoginScreen.h" //this is form1
.....


then i have this errors : http://prntscr.com/b2ucwo

what i do wrong? thanks :)
You need to pass a reference of form1 to form2. Try to set form1 as the parent of form2. In form2 you cast the parent to form and show or hide it.
you mean i need to put in form2 this code?

1
2
LoginScreen^ login = gcnew LoginScreen();
loginscreen->Show();

for example?
No, don't create a second form. Use the existing one. Have a look here, must read till the bottom.
http://stackoverflow.com/questions/14306430/child-form-calling-function-on-parent-in-net-c
i do this
HlavneMenu.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "PridanieTasku.h"
#include "Komentare.h"
#include "Trackovanie.h"
#include "UzavrietUlohu.h"

namespace MetrumPTT {
	ref class Trackovanie;
	
	public ref class HlavneMenu {
		HlavneMenu^ hlavnemenu;
	};

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;


and Trackovanie.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <adam.h>
#include <msclr\marshal_cppstd.h>
#include "HlavneMenu.h"

namespace MetrumPTT {
	ref class HlavneMenu;

	public ref class Trackovanie {
		Trackovanie^ hlavnemenu;
	};

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace MySql::Data::MySqlClient;
	using namespace std;
	using namespace msclr::interop;


Error is : http://prntscr.com/b3jrh5

How to solve this, i think the ref class i made wrong.
Last edited on
Topic archived. No new replies allowed.