Form Program
.NET(C#)ぷろぐらみんぐ フォームのサンプル Visual Studioもしくは .NET Framework SDKのcscで作成します
1. エディタ(notepad)で下記のソースを用意します。
file:Form.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Form {
public class Form : System.Windows.Forms.Form {
private System.Windows.Forms.Button button;
private System.ComponentModel.Container components = null;
public Form() {
InitializeComponent();
}
protected override void Dispose( bool disposing ) {
if( disposing ) {
if( components != null ) {
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Form Design
private void InitializeComponent() {
this.button = new System.Windows.Forms.Button();
this.SuspendLayout();
// button
this.button.Location = new System.Drawing.Point(40, 50);
this.button.Name = "button";
this.button.Size = new System.Drawing.Size(160, 20);
this.button.TabIndex = 0;
this.button.Text = "TEST";
this.button.Click += new System.EventHandler(this.button_click);
// Form
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(240, 100);
this.Name = "Form";
this.Text = "Form Sample";
this.ResumeLayout(false);
}
#endregion
///
/// Entry Point
///
[STAThread]
static void Main() {
Application.Run(new Form());
}
private void button_click(object sender, System.EventArgs e) {
MessageBox.Show("ボタンがクリックされました。", "テスト");
}
}
}
2. コンパイル
C:>csc Form.cs
3. 実行してみる
Form Sampleという小さなフォームが立ち上がります [TEST]ボタンをクリックするとメッセージボックスが 表示されます。![]()
簡単ですが .NET(C#)でフォームのプログラムをゼロから作る 手順を書いてみました