Skip to content

Instantly share code, notes, and snippets.

@fullmated
Created January 5, 2012 18:20
Show Gist options
  • Save fullmated/1566479 to your computer and use it in GitHub Desktop.
Save fullmated/1566479 to your computer and use it in GitHub Desktop.
using System;
using System.Windows.Forms;
class Sample1 : Form {
private Label lb, lb2;
private Button bt;
public static void Main() {
Application.Run( new Sample1() );
}
public Sample1() {
this.Text = "サンプル";
this.Width = 200; this.Height = 200;
lb = new Label();
lb.Text = "矢印キーを入力";
lb.Width = 150;
lb2 = new Label();
lb2.Text = "方向";
lb2.Top = lb.Bottom;
lb.Parent = this;
lb2.Parent = this;
// イベントハンドラを登録する
this.KeyDown += new KeyEventHandler( fm_KeyDown );
}
// イベントハンドラを定義する
public void fm_KeyDown( Object sender, KeyEventArgs e ) {
String str;
if ( e.KeyCode == Keys.Up ) {
str = "上";
} else if( e.KeyCode == Keys.Down ) {
str = "下";
} else if( e.KeyCode == Keys.Left ) {
str = "左";
} else if( e.KeyCode == Keys.Right ) {
str = "右";
} else {
str = "他のキー";
}
lb2.Text = str + "ですね。";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment