我不熟悉visual C ++,所以我使用.NET框架编译了一个简单的程序来找到它的方法。
#pragma once
namespace Netattempt2 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ txtbxUsername;
private: System::Windows::Forms::Button^ btnClick;
protected:
protected:
private: System::Windows::Forms::Label^ label1;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->txtbxUsername = (gcnew System::Windows::Forms::TextBox());
this->btnClick = (gcnew System::Windows::Forms::Button());
this->label1 = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// txtbxUsername
//
this->txtbxUsername->Location = System::Drawing::Point(94, 17);
this->txtbxUsername->Name = L"txtbxUsername";
this->txtbxUsername->Size = System::Drawing::Size(174, 20);
this->txtbxUsername->TabIndex = 0;
//
// btnClick
//
this->btnClick->Location = System::Drawing::Point(204, 43);
this->btnClick->Name = L"btnClick";
this->btnClick->Size = System::Drawing::Size(64, 23);
this->btnClick->TabIndex = 1;
this->btnClick->Text = L"Click Me!";
this->btnClick->UseVisualStyleBackColor = true;
this->btnClick->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(12, 20);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(76, 13);
this->label1->TabIndex = 2;
this->label1->Text = L"Enter name -->";
this->label1->Click += gcnew System::EventHandler(this, &Form1::label1_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 73);
this->Controls->Add(this->label1);
this->Controls->Add(this->btnClick);
this->Controls->Add(this->txtbxUsername);
this->Name = L"Form1";
this->Text = L"Hello World!";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void btnClick_Click(System::Object^ sender, System::EventArgs^ e) {
MessageBox.Show("Welcome to windows " + txtbxUsername.Text, "Hi there...");
}
};
}
这一行:
MessageBox.Show("Welcome to windows " + txtbxUsername.Text, "Hi there...");
返回此错误:
Form1.h(114) : error C2143: syntax error : missing ';' before '.'
取出该行允许程序编译,但该程序或多或少都需要消息框。
有谁知道这里出了什么问题?
答案 0 :(得分:4)
更改为
MessageBox::Show("Welcome to windows " + txtbxUsername->Text, "Hi there...");
^^ ^^