【问题标题】:I'm getting an error and im not sure why? [closed]我收到一个错误,我不知道为什么? [关闭]
【发布时间】:2015-11-17 16:57:52
【问题描述】:

这是出现错误的代码部分。

#include "MyForm.h"
; using namespace System;
using namespace System::Windows::Forms;

[STAThread]
void main(array<String^>^ args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

V_Hello_World::MyForm form;
Application::Run(%form);
}

错误是:错误 1 ​​错误 C1075:在左大括号“{”之前找到文件结尾。我不确定为什么会发生此错误,但非常感谢一些帮助。

MyForm.h

#pragma once

namespace V_Hello_World {

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 MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
    MyForm(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }

    protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~MyForm()
    {
        if (components)
        {
            delete components;
        }
    }
    private: System::Windows::Forms::Button^  button1;
    protected:

    protected:

    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->button1 = (gcnew System::Windows::Forms::Button());
        this->SuspendLayout();
        // 
        // button1
        // 
        this->button1->Font = (gcnew System::Drawing::Font(L"Minion  Pro", 14.25F, System::Drawing::FontStyle::Bold,   System::Drawing::GraphicsUnit::Point,
            static_cast<System::Byte>(0)));
        this->button1->Location = System::Drawing::Point(12, 12);
        this->button1->Name = L"button1";
        this->button1->Size = System::Drawing::Size(260, 237);
        this->button1->TabIndex = 0;
        this->button1->Text = L"Say Hello";
        this->button1->UseVisualStyleBackColor = true;
        this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
        // 
        // MyForm
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(284, 261);
        this->Controls->Add(this->button1);
        this->Name = L"MyForm";
        this->Text = L"MyForm";
        this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
        this->ResumeLayout(false);

    }
#pragma endregion
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    {
        MessageBox::Show("Hello World!");
    }
};
private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) {
}
}

【问题讨论】:

  • 问题可能出在"MyForm.h"
  • 这是 C++/CLI 和 WinForms,而不是 C++。
  • 您可以将"MyForm.h" 的内容添加到您的问题中吗?
  • 我已经添加了 MyForm.h

标签: .net winforms visual-c++ c++-cli


【解决方案1】:

你开始运行问题

#pragma endregion
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    {
        MessageBox::Show("Hello World!");
    }
};
private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) {
}
}

您的第一个问题是button1_Click 有两个左大括号,但只有一个右大括号。您应该能够删除其中一个打开的花括号。您的第二个问题是MyForm_Load 不在课程主体内。您需要将其移至类声明中。

【讨论】:

  • 我试图删除两个括号,而不是同时删除,当我这样做时,它开始用红色强调一堆其他东西,说它是错误的。
  • @Punny 你明白了吗?我看到你把接受标记放在答案上。
  • 我想大多数情况下是的,但原来的错误再次出现,我想我会离开你们,继续努力解决这个问题。对不起,如果我浪费了你的任何时间。 ;/
猜你喜欢
  • 1970-01-01
  • 2017-11-23
  • 2019-02-14
  • 2020-03-20
  • 1970-01-01
  • 1970-01-01
  • 2020-08-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多