错误C2227:“->文本”的左侧必须指向类/结构/联合/泛型类型

优素福

当我按F5键启动应用程序时,出现c2227错误,我不知道如何解决, - - - - - - - - - - - - - - - - - - - - - - 输出:

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;
                 }
             }
};
}

有解决这个问题的主意吗?

本·沃格特

由于static某种原因,您的事件处理程序被声明为这意味着,像所有静态成员函数一样,它们不能使用不合格的非静态成员。因此,不能使用名称bytesrecievedtotalbytesrecieved等等(其名称拼写错误)。

您几乎总是希望事件处理程序使用非静态成员函数。

代替

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

你需要

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

static从的声明中删除关键字DownloadProgressChanged

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

解决Java的泛型类型的错误与抽象类方法

TypeScript泛型错误:算术运算的左侧必须为“ any”,“ number”,“ bigint”类型

gcc错误:字串长度太大(C11类型泛型)

泛型错误:预期类型参数,找到结构

C ++类中的任何泛型类型

在C#的泛型类中获取嵌套泛型类的类型

C#泛型类型类无法获取属性值

带有其他类型属性的泛型集合的C#泛型类

.setDay'左边的错误C2228必须具有类/结构/联合

C#泛型错误-类型字符串必须不可为空

泛型类型参数C#-如何泛型类返回类型

Typescript-联合类型和泛型类型引发不兼容错误

C#泛型:如何声明一个泛型,其中2个集合必须包含相同的类型,但是这些集合不必是同一类型

具有联合类型抛出的泛型无法分配错误

C结构,指向结构的联合指针

访问单元格文本时出现错误C3293,C2227

如果泛型类型约束还必须在c#中实现接口,则类类型约束将实现什么?

C#将类类型的字典传递给泛型

C2227:“->发送”的左侧必须指向类/结构/联合/泛型类型

创建具有泛型值的列表时出现错误“表达式必须具有类类型”

存储泛型 T 类型类的 C++ 向量

c#获取泛型类中泛型类型参数的名称

控制器错误 ErrorExtension 方法必须在非泛型静态类中定义

错误(E0852)表达式必须是指向完整对象类型(泛型链表)的指针

C# 类中泛型类型的泛型属性设置器

类 C# 中的多个泛型类型字段

当T是类或原始类型时的c#泛型约束

C#泛型类类型参数和与泛型参数相同的约束

C#如何在泛型类中访问泛型类型的成员?