2014-12-27 45 views
0

當我按F5啓動應用程序時,我得到c2227錯誤 我不知道如何解決它,--- -------------------------------------------------- ------------------- 輸出:錯誤C2227:' - > Text'左邊必須指向class/struct/union/generic類型

1>------ Build started: Project: YM! Download Manager, Configuration: Debug Win32 ------ 
1> YM! Download Manager.cpp 
1>c:\users\youssef\documents\visual studio 2010\projects\ym! download manager\ym! download manager\Form1.h(289): error C2227: left of '->Text' must point to class/struct/union/generic type 
1>c:\users\youssef\documents\visual studio 2010\projects\ym! download manager\ym! download manager\Form1.h(290): error C2227: left of '->Text' must point to class/struct/union/generic type 
1>c:\users\youssef\documents\visual studio 2010\projects\ym! download manager\ym! download manager\Form1.h(291): error C2227: left of '->Text' must point to class/struct/union/generic type 
1>c:\users\youssef\documents\visual studio 2010\projects\ym! download manager\ym! download manager\Form1.h(292): error C2227: left of '->Value' must point to class/struct/union/generic type 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========` 

代碼: Form1.h

#pragma once 

namespace YMDownloadManager { 

    using namespace System; 
    using namespace System::ComponentModel; 
    using namespace System::Collections; 
    using namespace System::Windows::Forms; 
    using namespace System::Data; 
    using namespace System::Drawing; 
    using namespace System::Net; 

    /// <summary> 
    /// Summary for Form1 
    /// </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::GroupBox^ groupBox1; 
    protected: 
    private: System::Windows::Forms::Button^ button2; 
    private: System::Windows::Forms::Button^ button1; 
    private: System::Windows::Forms::TextBox^ textBox2; 
    private: System::Windows::Forms::TextBox^ textBox1; 
    private: System::Windows::Forms::Label^ label2; 
    private: System::Windows::Forms::Label^ label1; 
    private: System::Windows::Forms::GroupBox^ groupBox2; 
    private: System::Windows::Forms::ProgressBar^ progress; 

    private: System::Windows::Forms::Label^ label6; 
    private: System::Windows::Forms::Label^ label5; 
    private: System::Windows::Forms::Label^ label4; 
    private: System::Windows::Forms::Label^ label3; 
    private: System::Windows::Forms::Label^ bytesrecieved; 
    private: System::Windows::Forms::Label^ totalbytesrecieved; 
    private: System::Windows::Forms::Label^ percent; 

    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) 
     { 
      System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); 
      this->groupBox1 = (gcnew System::Windows::Forms::GroupBox()); 
      this->button2 = (gcnew System::Windows::Forms::Button()); 
      this->button1 = (gcnew System::Windows::Forms::Button()); 
      this->textBox2 = (gcnew System::Windows::Forms::TextBox()); 
      this->textBox1 = (gcnew System::Windows::Forms::TextBox()); 
      this->label2 = (gcnew System::Windows::Forms::Label()); 
      this->label1 = (gcnew System::Windows::Forms::Label()); 
      this->groupBox2 = (gcnew System::Windows::Forms::GroupBox()); 
      this->percent = (gcnew System::Windows::Forms::Label()); 
      this->bytesrecieved = (gcnew System::Windows::Forms::Label()); 
      this->totalbytesrecieved = (gcnew System::Windows::Forms::Label()); 
      this->progress = (gcnew System::Windows::Forms::ProgressBar()); 
      this->label6 = (gcnew System::Windows::Forms::Label()); 
      this->label5 = (gcnew System::Windows::Forms::Label()); 
      this->label4 = (gcnew System::Windows::Forms::Label()); 
      this->label3 = (gcnew System::Windows::Forms::Label()); 
      this->groupBox1->SuspendLayout(); 
      this->groupBox2->SuspendLayout(); 
      this->SuspendLayout(); 
      // 
      // groupBox1 
      // 
      this->groupBox1->Controls->Add(this->button2); 
      this->groupBox1->Controls->Add(this->button1); 
      this->groupBox1->Controls->Add(this->textBox2); 
      this->groupBox1->Controls->Add(this->textBox1); 
      this->groupBox1->Controls->Add(this->label2); 
      this->groupBox1->Controls->Add(this->label1); 
      this->groupBox1->Location = System::Drawing::Point(12, 12); 
      this->groupBox1->Name = L"groupBox1"; 
      this->groupBox1->Size = System::Drawing::Size(299, 124); 
      this->groupBox1->TabIndex = 0; 
      this->groupBox1->TabStop = false; 
      // 
      // button2 
      // 
      this->button2->Font = (gcnew System::Drawing::Font(L"Franklin Gothic Medium", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
       static_cast<System::Byte>(0))); 
      this->button2->Location = System::Drawing::Point(268, 54); 
      this->button2->Name = L"button2"; 
      this->button2->Size = System::Drawing::Size(25, 20); 
      this->button2->TabIndex = 7; 
      this->button2->Text = L"..."; 
      this->button2->UseVisualStyleBackColor = true; 
      this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click); 
      // 
      // button1 
      // 
      this->button1->Font = (gcnew System::Drawing::Font(L"Courier New", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
       static_cast<System::Byte>(0))); 
      this->button1->Location = System::Drawing::Point(110, 95); 
      this->button1->Name = L"button1"; 
      this->button1->Size = System::Drawing::Size(75, 23); 
      this->button1->TabIndex = 6; 
      this->button1->Text = L"Download"; 
      this->button1->UseVisualStyleBackColor = true; 
      this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); 
      // 
      // textBox2 
      // 
      this->textBox2->Location = System::Drawing::Point(63, 54); 
      this->textBox2->Name = L"textBox2"; 
      this->textBox2->Size = System::Drawing::Size(205, 20); 
      this->textBox2->TabIndex = 5; 
      // 
      // textBox1 
      // 
      this->textBox1->Location = System::Drawing::Point(39, 25); 
      this->textBox1->Name = L"textBox1"; 
      this->textBox1->Size = System::Drawing::Size(253, 20); 
      this->textBox1->TabIndex = 4; 
      // 
      // label2 
      // 
      this->label2->AutoSize = true; 
      this->label2->Font = (gcnew System::Drawing::Font(L"Courier New", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
       static_cast<System::Byte>(0))); 
      this->label2->Location = System::Drawing::Point(5, 57); 
      this->label2->Name = L"label2"; 
      this->label2->Size = System::Drawing::Size(63, 14); 
      this->label2->TabIndex = 2; 
      this->label2->Text = L"Save To:"; 
      // 
      // label1 
      // 
      this->label1->AutoSize = true; 
      this->label1->Font = (gcnew System::Drawing::Font(L"Courier New", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
       static_cast<System::Byte>(0))); 
      this->label1->Location = System::Drawing::Point(8, 28); 
      this->label1->Name = L"label1"; 
      this->label1->Size = System::Drawing::Size(35, 14); 
      this->label1->TabIndex = 1; 
      this->label1->Text = L"URL:"; 
      // 
      // groupBox2 
      // 
      this->groupBox2->Controls->Add(this->percent); 
      this->groupBox2->Controls->Add(this->bytesrecieved); 
      this->groupBox2->Controls->Add(this->totalbytesrecieved); 
      this->groupBox2->Controls->Add(this->progress); 
      this->groupBox2->Controls->Add(this->label6); 
      this->groupBox2->Controls->Add(this->label5); 
      this->groupBox2->Controls->Add(this->label4); 
      this->groupBox2->Controls->Add(this->label3); 
      this->groupBox2->Font = (gcnew System::Drawing::Font(L"Courier New", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
       static_cast<System::Byte>(0))); 
      this->groupBox2->Location = System::Drawing::Point(12, 152); 
      this->groupBox2->Name = L"groupBox2"; 
      this->groupBox2->Size = System::Drawing::Size(299, 100); 
      this->groupBox2->TabIndex = 0; 
      this->groupBox2->TabStop = false; 
      this->groupBox2->Text = L"Status"; 
      // 
      // percent 
      // 
      this->percent->AutoSize = true; 
      this->percent->Location = System::Drawing::Point(117, 11); 
      this->percent->Name = L"percent"; 
      this->percent->Size = System::Drawing::Size(49, 14); 
      this->percent->TabIndex = 7; 
      this->percent->Text = L"label7"; 
      // 
      // bytesrecieved 
      // 
      this->bytesrecieved->AutoSize = true; 
      this->bytesrecieved->Location = System::Drawing::Point(127, 29); 
      this->bytesrecieved->Name = L"bytesrecieved"; 
      this->bytesrecieved->Size = System::Drawing::Size(0, 14); 
      this->bytesrecieved->TabIndex = 6; 
      // 
      // totalbytesrecieved 
      // 
      this->totalbytesrecieved->AutoSize = true; 
      this->totalbytesrecieved->Location = System::Drawing::Point(106, 55); 
      this->totalbytesrecieved->Name = L"totalbytesrecieved"; 
      this->totalbytesrecieved->Size = System::Drawing::Size(0, 14); 
      this->totalbytesrecieved->TabIndex = 5; 
      // 
      // progress 
      // 
      this->progress->Location = System::Drawing::Point(6, 73); 
      this->progress->Name = L"progress"; 
      this->progress->Size = System::Drawing::Size(287, 19); 
      this->progress->TabIndex = 4; 
      // 
      // label6 
      // 
      this->label6->AutoSize = true; 
      this->label6->Location = System::Drawing::Point(243, 55); 
      this->label6->Name = L"label6"; 
      this->label6->Size = System::Drawing::Size(56, 14); 
      this->label6->TabIndex = 3; 
      this->label6->Text = L"Byte(s)"; 
      // 
      // label5 
      // 
      this->label5->AutoSize = true; 
      this->label5->Location = System::Drawing::Point(8, 55); 
      this->label5->Name = L"label5"; 
      this->label5->Size = System::Drawing::Size(91, 14); 
      this->label5->TabIndex = 2; 
      this->label5->Text = L"Total Bytes:"; 
      // 
      // label4 
      // 
      this->label4->AutoSize = true; 
      this->label4->Location = System::Drawing::Point(243, 29); 
      this->label4->Name = L"label4"; 
      this->label4->Size = System::Drawing::Size(56, 14); 
      this->label4->TabIndex = 1; 
      this->label4->Text = L"Byte(s)"; 
      // 
      // label3 
      // 
      this->label3->AutoSize = true; 
      this->label3->Location = System::Drawing::Point(8, 29); 
      this->label3->Name = L"label3"; 
      this->label3->Size = System::Drawing::Size(112, 14); 
      this->label3->TabIndex = 0; 
      this->label3->Text = L"Bytes Recieved:"; 
      // 
      // Form1 
      // 
      this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); 
      this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; 
      this->ClientSize = System::Drawing::Size(323, 264); 
      this->Controls->Add(this->groupBox2); 
      this->Controls->Add(this->groupBox1); 
      this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle; 
      this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon"))); 
      this->Name = L"Form1"; 
      this->Text = L"YM! Download Manager"; 
      this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load); 
      this->groupBox1->ResumeLayout(false); 
      this->groupBox1->PerformLayout(); 
      this->groupBox2->ResumeLayout(false); 
      this->groupBox2->PerformLayout(); 
      this->ResumeLayout(false); 

     } 
#pragma endregion 
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { 
        WebClient^ client = gcnew WebClient(); 
      client->DownloadProgressChanged += gcnew DownloadProgressChangedEventHandler(DownloadProgressChanged); 
      client->DownloadFileCompleted += gcnew AsyncCompletedEventHandler(DownloadComplete); 
      client->DownloadFileAsync(gcnew Uri(textBox1->Text), textBox2->Text); 
      } 
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { 
       bytesrecieved->BringToFront(); 
      totalbytesrecieved->BringToFront(); 
      progress->BringToFront(); 
      percent->BringToFront(); 
      bytesrecieved->Text = L"......................................"; 
      totalbytesrecieved->Text = L"................................."; 
      percent->Text = L"... %"; 
     } 
     static void DownloadProgressChanged(System::Object^ sender, DownloadProgressChangedEventArgs^ e) 
     { 
      bytesrecieved->Text = e->BytesReceived.ToString(); 
      totalbytesrecieved->Text = e->TotalBytesToReceive.ToString(); 
      percent->Text = e->ProgressPercentage.ToString() + " %"; 
      progress->Value = e->ProgressPercentage; 
     } 
      static void DownloadComplete(System::Object^ sender, AsyncCompletedEventArgs^ e) 
     { 
      MessageBox::Show("Download Has Completed Successfully!", "Message From Program", 
       MessageBoxButtons::OK, MessageBoxIcon::Information); 
     } 
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { 
      SaveFileDialog^ save = gcnew SaveFileDialog(); 
       save->Title = "Choose A Location For The Download To Save To."; 
       if (save->ShowDialog() == Windows::Forms::DialogResult::OK) 
       { 
        textBox2->Text = save->FileName; 
       } 
      } 
}; 
} 

任何想法來解決這個問題?

+0

而是粘貼所有代碼的聲明中刪除static關鍵字,減少代碼量最少這仍然代表你的問題。 – 2014-12-27 17:15:33

回答

1

出於某種原因,您的事件處理程序被聲明爲static。這意味着,像所有靜態成員函數一樣,它們不能使用不合格的非靜態成員。所以名稱bytesrecievedtotalbytesrecieved等(這是拼錯btw)不能使用。

您幾乎總是希望事件處理程序使用非靜態成員函數。

而不是

client->DownloadProgressChanged += gcnew DownloadProgressChangedEventHandler(DownloadProgressChanged); 

你需要

client->DownloadProgressChanged += gcnew DownloadProgressChangedEventHandler(this, &Form1::DownloadProgressChanged); 

,並從DownloadProgressChanged

+0

非常感謝 – Youssef 2014-12-27 20:17:15

相關問題