Okay! I endlly got it by myself. As said, it's not such easy to use "set" & "get"
under C++/WinForm. You always need a class for the variables to be transfered. Because normal global variables are not any more possible to declare.
And make sure "using namespace System" to be included.
So, see my codes if it would help you:
GlobalClass.h:
#pragma once
namespace Globals
{
using namespace System;
public ref class GlobalClass
{
public: static String^ g_STR;
};
}
Form1.h:
#pragma once
#include "Form2.h"
#include "GlobalClass.h"
namespace TEST {
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 Globals;
...
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
GlobalClass::g_STR = textBox1->Text;
}
...
Save the value of textBox1 into the global string g_STR. With a button click to show Form2(method Show() or ShowDialog()).
Form2.h:
#pragma once
#include "GlobalClass.h"
namespace TEST {
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 Globals;
...
private: System::Void Form2_Load(System::Object^ sender, System::EventArgs^ e) {
label1->Text=GlobalClass::g_STR;
}
...
When Form2 is loaded, then label1 will show us the value of textBox1 from Form1.
Which is acturally transfered per g_STR.
There is also an article which says that it differs when you use Show()(modeless) as ShowDialog()(modal). But i didn't prove this. See link:
http://www.dreamincode.net/forums/topic/206458-how-to-get-values-from-form1-to-form2-or-any-other-forms/[
^]
In conclusion, this method is for making a global variables class under C++/CLR/WinForm that helps you to get variables from one form to another.
I'm pleasured if this helps.