【发布时间】:2017-05-05 09:54:16
【问题描述】:
我正在使用 Visual C++ 2010 Express。我有一个包含文本框 (textBox1) 的表单 (Form1.h)。
我希望另一个 test.cpp 能够访问 textBox1 并显示消息。
我有类似的东西:
在 Form1.h 中
... standard form code generated by Visual Studio
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
textBox1->Text = "Connecting to server ...";
}
在 test.cpp 中包含类似
....
void write (const unsigned char *data, int length)
{
System::Windows::Forms::textBox1->Text = "Send failed";
}
....
编译后出现如下错误:
- 'textBox1' : 不是'System::Windows::Forms'的成员
- 'textBox1':未声明的标识符
- '->Text' 的左边必须指向类/结构/联合/泛型类型
- 语法错误:缺少';'在“字符串”之前
我是 Visual C++ 的新手,不知道如何正确访问类/对象。 提前感谢您的帮助。
【问题讨论】: