在form中追加文本

C++ : Appending text in form

本文关键字:文本 追加 form      更新时间:2023-10-16

我已经离开c++有一段时间了,这可能只是我的愚蠢,但为什么这会给我一个错误(代码下面的错误)

代码:

// NetworkServer.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
#include <winsock2.h>
#include <iostream>
using namespace std;
using namespace NetworkServer;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false); 
// Create the main window and run it
Application::Run(gcnew Form1());

    public void setUsers()
{
    string connectedUsers[] = {"John", "Alex", "Phillip", "Steve"};
    Form1->txt_connectedClients.AppendText(connectedUsers[1]);
}
    return 0;
}

错误:

    1>NetworkServer.cpp(22): error C2143: syntax error : missing ';' before '->'
    1>NetworkServer.cpp(22): error C2143: syntax error : missing ';' before '->'

Form1是类型名称,需要对象。我看不到代码的上下文,但只要这段代码是在Form1类的方法中编写的,那么这个->将工作。

public ref class Form1 : public System::Windows::Forms::Form
{
   //...
public:
    void setUsers() {
        array<String^>^ connectedUsers = gcnew array<String^> {"John", "Alex", "Phillip", "Steve"};
        this->txt_connectedClients->AppendText(connectedUsers[1]);
    }
};

注意你是在用c++/CLI语言编程,而不是c++。

txt_connectedClients不存在或不是一个指针。