Winforms 简单的GUI不起作用。[C+;+;]
我只是在我的书中键入所有类似示例的内容。你能告诉我为什么它不工作吗 谢谢你的关注Winforms 简单的GUI不起作用。[C+;+;],winforms,c++-cli,Winforms,C++ Cli,我只是在我的书中键入所有类似示例的内容。你能告诉我为什么它不工作吗 谢谢你的关注 这是布局。 // Example_1.cpp : main project file. #include "stdafx.h" #include "Form1.h" using namespace Example_1; [STAThreadAttribute] int main(array<System::String ^> ^args) { // Enabling Windows XP
这是布局。
// Example_1.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
using namespace Example_1;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
#pragma once
namespace Example_1 {
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
/// </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::Button^ button1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::TextBox^ textBox1;
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->label1 = (gcnew System::Windows::Forms::Label());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(154, 74);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(104, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"OK";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(12, 9);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(118, 13);
this->label1->TabIndex = 1;
this->label1->Text = L"Please enter you name.";
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(15, 35);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(243, 20);
this->textBox1->TabIndex = 2;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(273, 110);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->label1);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e) {
String^ message = "Hello";
String^ title = "Welcome";
MessageBox::Show( message, title, MessageBoxButtons::OK );
}
};
}
1>------ Build started: Project: Example_1, Configuration: Debug Win32 ------
1>Build started 02-Feb-14 6:28:11 PM.
1>InitializeBuildStatus:
1> Touching "Debug\Example_1.unsuccessfulbuild".
1>GenerateTargetFrameworkMonikerAttribute:
1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>ClCompile:
1> All outputs are up-to-date.
1> Example_1.cpp
1>c:\users\user\desktop\example_1\example_1\Form1.h(108): error C2653: 'MessageBoxButton' : is not a class or namespace name
1>c:\users\user\desktop\example_1\example_1\Form1.h(108): error C2065: 'OK' : undeclared identifier
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.88
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
这是示例\u 1.cpp。
// Example_1.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
using namespace Example_1;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
#pragma once
namespace Example_1 {
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
/// </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::Button^ button1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::TextBox^ textBox1;
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->label1 = (gcnew System::Windows::Forms::Label());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(154, 74);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(104, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"OK";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(12, 9);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(118, 13);
this->label1->TabIndex = 1;
this->label1->Text = L"Please enter you name.";
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(15, 35);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(243, 20);
this->textBox1->TabIndex = 2;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(273, 110);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->label1);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e) {
String^ message = "Hello";
String^ title = "Welcome";
MessageBox::Show( message, title, MessageBoxButtons::OK );
}
};
}
1>------ Build started: Project: Example_1, Configuration: Debug Win32 ------
1>Build started 02-Feb-14 6:28:11 PM.
1>InitializeBuildStatus:
1> Touching "Debug\Example_1.unsuccessfulbuild".
1>GenerateTargetFrameworkMonikerAttribute:
1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>ClCompile:
1> All outputs are up-to-date.
1> Example_1.cpp
1>c:\users\user\desktop\example_1\example_1\Form1.h(108): error C2653: 'MessageBoxButton' : is not a class or namespace name
1>c:\users\user\desktop\example_1\example_1\Form1.h(108): error C2065: 'OK' : undeclared identifier
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.88
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
您忘记了MessageBox类的命名空间:
using namespace System::Windows;
也许可以试试这个:
系统::Windows::窗体::MessageBox
这是:
系统::Windows::窗体::MessageBox按钮
(你忘了带s)
链接:
和
什么是“MessageBoxButton”?对不起。应该是MessageBoxButtons。它使代码中的错误消失了。在哪里添加此语句?“Eample_1.cpp”或“Form1.h”?看起来这两个文件都不可行。Thank.1>TRACKER:错误TRK0002:未能执行命令:“C:\Program Files(x86)\Microsoft Visual Studio 10.0\VC\bin\CL.exe”@C:\Users\User\AppData\Local\Temp\TMPAB12CE06007FA4AFABB059350E07538E.rsp”。存储控制块地址无效。如何解决这个问题?这似乎是一个无关的问题,提出另一个问题并发布它