2012-08-04 114 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

相關問題