2012-08-04 110 views
1

我对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

请注意,这不是C++:这是C++/CLI。 – 2012-08-04 21:38:01

回答

4

更改为

MessageBox::Show("Welcome to windows " + txtbxUsername->Text, "Hi there..."); 
      ^^           ^^ 
+0

'txtbxUsername.Text'也需要'txtbxUsername-> Text',我想。 – 2012-08-04 22:00:57

+0

@JamesMcNellis,是的,谢谢我的眼睛有点疲倦,停下来第一个。我想,该睡觉了。 – Steve 2012-08-04 22:03:25

+0

谢谢。这固定了一切。我想知道C++和C#语法之间的一些区别,因为我想到了这一点。 – user1576628 2012-08-04 22:15:17

相关问题