1

如何从表单类外部在richTextBox 中输入文本?

我的项目中有四个文件: Form1.h Form1.cpp Main.cpp Importfile.cpp

在 form1.cpp 我使用这个函数:

System::Void Form1::SendText_Click(System::Object^  sender, System::EventArgs^  e) 
{
    info_function();
}

在 Importfile.cpp 中,我尝试使用以下代码编写文本:

#include "Form1.h"
#include "Importfile.h"

using namespace Forms_test; // the namespace where my Form class is in

void info_function()
{   
    //Form1->richTextBox1.AppendText("Starting slaveinfo\n");
    //formpointer->richTextBox1->AppendText("Starting slaveinfo\n");
    //richTextBox1->AppendText("Starting slaveinfo\n");
    // I tried all three.
}   

在我的主文件中,我开始这样的表格:

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

Form1^ formpointer = (gcnew Form1());
Application::Run(formpointer);

我这样做是为了可以使用表单指针以某种方式访问​​我的richtextbox。

我的问题是,当我尝试构建时出现错误:“'-> AppendText' 的左侧必须指向类/结构/联合/通用类型”

我在想它以某种方式找不到我的richTextBox 指针,但我怎样才能确保它可以呢?我知道可能还有更多类似这样的问题,但不知何故我似乎找不到它们。

提前致谢。

4

0 回答 0