【发布时间】:2013-03-30 02:36:55
【问题描述】:
我有一个 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
编辑:
我就是这样解决的
这就是我修复它的方法。
Form1.h
#include "Form1.h"
Form2^ frm = gcnew Form2;
frm->Username = "text here";//This passes the variables.
frm->Password = "other text";
Form2.h
public: String^ Username;
public: String^ Password;
【问题讨论】:
-
为了帮助您,我们需要查看您遇到问题的代码。
-
Form2.h中包含Form1.h直接访问? Form2 是一个变量,您可以通过在 Form1.h 中包含 Form2.h 来访问变量 Form2。它适用于两种方式;)
-
@The_aLiEn 实际上。它只是给了我一个错误,因为我猜你不能有 2 个文件,包括彼此。
-
让我猜猜,“圆形单位参考”?
-
Idk 那是什么但是当我将 Form1.h 包含到 Form2.h 时它不起作用:\