I can't include instance of global form variable in user control. Makes errors.

In Program.h is ProgramItems ref class which has static Window ^window (form). I want to include it in Search.h (user control), so from it I can add controls to window and other stuff. But, when I include "Program.h" in Search.h i get different errors on compile. Basicly all I want to do is to have global window variable that works for any usercontrol in my program.
Here is my code:

Program.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "Window.h"
#include "Program.h"

using namespace System;
using namespace System::Windows::Forms;

[STAThread]
int main() {

	Application::EnableVisualStyles();
	
	Application::SetCompatibleTextRenderingDefault(false);

	ProgramItems::window = gcnew SMSALENalozi::Window();

	Application::Run(ProgramItems::window);

	return 0;
}


Program.h:
1
2
3
4
5
6
7
8
9
10
11
#pragma once

#include "Window.h"

ref class ProgramItems {

public:

	static SMSALENalozi::Window ^window;

};


Window.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once

#include "Search.h" //When include it makes errors.

namespace SMSALENalozi {

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

	/// <summary>
	/// Summary for Window
	/// </summary>
	public ref class Window : public System::Windows::Forms::Form
	{
	public:
		Window()
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Window()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::PictureBox^  menu_background_picturebox;
	private: System::Windows::Forms::PictureBox^  logo_picturebox;
	private: System::Windows::Forms::Label^  ulogujse_label;
	private: System::Windows::Forms::TextBox^  passwordwriting_textbox;
        ...OTHER FORM CODE.
	private: System::Void passwordwriting_textbox_KeyPress(System::Object^  sender, System::Windows::Forms::KeyPressEventArgs^  e) {

		if (e->KeyChar == (char)13) {

			if (passwordwriting_textbox->Text == "KRASTA") {

				Search ^search = gcnew Search();

				this->Controls->Clear();

				this->Controls->Add(search);

				search->Focus();

				e->Handled = true;

			}

		}

	}
};
}


Search.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once

#include "Program.h"

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

namespace SMSALENalozi {

	/// <summary>
	/// Summary for Search
	/// </summary>
	public ref class Search : public System::Windows::Forms::UserControl
	{
	public:
		Search(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			trazi_label->Parent = search_background_picturebox;
			searchby_combobox->SelectedIndex = 0;
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Search()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::PictureBox^  search_background_picturebox;
	protected:

	private: System::Windows::Forms::Label^  trazi_label;
	private: System::Windows::Forms::TextBox^  accountwriting_textbox;
        ...OTHER CODE
	private: System::Void accountwriting_textbox_PreviewKeyDown(System::Object^  sender, System::Windows::Forms::PreviewKeyDownEventArgs^  e) {

		if (e->KeyCode == Keys::Enter) {

			this->Hide();

		}

	}
};
}


Thanks :).
Last edited on
You may have better luck asking this in the Windows programming forum, seeing as you're not using standard C++.
You are right.
Topic archived. No new replies allowed.