Created
January 5, 2012 18:22
-
-
Save fullmated/1566490 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
bt = new Button(); | |
bt.Text = "ほげほげ"; | |
bt.Top = this.Top + lb.Height + 100; | |
lb.Parent = this; | |
lb2.Parent = this; | |
bt.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