開発環境 |
Microsoft Visual C++ 2010 Express (SP1) |
実行環境 |
Microsoft Windows XP Home Edition (SP3) |
プロジェクトの種類 |
空の CLR プロジェクト |
プロジェクト名 |
ClrForm |
参考
ClrForm.cpp
// コンソールを表示しない
// リンカー/システム/サブシステム:Windows (/SUBSYSTEM:WINDOWS)
// リンカー/詳細設定/エントリ ポイント:main
#pragma comment(linker, "/subsystem:windows")
#pragma comment(linker, "/entry:main")
// アセンブリ ※プロジェクトへの参照の追加(.NET)でも可
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#include "Form1.h"
using namespace ClrForm;
[STAThread] // Single-Threaded Apartment
int main()
{
// コントロールが作成される前に、Windows XP ビジュアル効果を有効にします
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// メイン ウィンドウを作成して、実行します
Application::Run(gcnew Form1());
return 0;
}
Form1.h
#pragma once
namespace ClrForm
{
using namespace System;
using namespace System::Drawing;
using namespace System::Windows;
using namespace System::Windows::Forms;
public ref class Form1 : public Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
}
private:
Label^ label1;
TextBox^ textBox1;
Button^ button1;
void InitializeComponent(void)
{
label1 = gcnew Label();
textBox1 = gcnew TextBox();
button1 = gcnew Button();
SuspendLayout();
// label1
label1->AutoSize = true;
label1->Location = Point(12, 9);
label1->Name = L"label1";
label1->Size = Drawing::Size(35, 12);
label1->TabIndex = 0;
label1->Text = L"label1";
// textBox1
textBox1->Location = Point(12, 24);
textBox1->Name = L"textBox1";
textBox1->Size = Drawing::Size(72, 19);
textBox1->TabIndex = 1;
textBox1->Text = L"textBox1";
// button1
button1->Location = Point(12, 49);
button1->Name = L"button1";
button1->Size = Drawing::Size(72, 27);
button1->TabIndex = 2;
button1->Text = L"button1";
button1->UseVisualStyleBackColor = true;
button1->Click += gcnew EventHandler(this, &Form1::button1_Click);
// Form1
AutoScaleDimensions = SizeF(6, 12);
AutoScaleMode = Forms::AutoScaleMode::Font;
ClientSize = Drawing::Size(292, 273);
Controls->Add(label1);
Controls->Add(textBox1);
Controls->Add(button1);
Name = L"Form1";
Text = L"Form1";
ResumeLayout(false);
PerformLayout();
}
Void button1_Click(Object^ sender, EventArgs^ e)
{
label1->Text = textBox1->Text;
MessageBox::Show(L"hello, world", L"MessageBox");
}
};
}
最終更新:2012年09月28日 17:17