我有一个 Form1.h 和一个 Form2.h
Form1.h 已经包含 Form2.h,因为我通过单击 Form1 中的按钮来启动 Form2。那么我如何将变量从 Form1.h 传递到 Form2.h
这是 Form1.h 的示例
#include "Form2.h"
String^ str = "Hello World"; //This variable needs to be passed to Form2.h
//Other windows forms application code here
Form2.h 的一个例子
//#include "Form1.h" this will cause an error
//How would i pass variable str to here?
//Other windows forms application code here
编辑:
这就是我修复它的方法
这就是我修复它的方式。
表格1.h
#include "Form1.h"
Form2^ frm = gcnew Form2;
frm->Username = "text here";//This passes the variables.
frm->Password = "other text";
表格2.h
public: String^ Username;
public: String^ Password;