Skip to content

Instantly share code, notes, and snippets.

@kazuooooo
Created December 30, 2014 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazuooooo/89488b180c1728ceabc2 to your computer and use it in GitHub Desktop.
Save kazuooooo/89488b180c1728ceabc2 to your computer and use it in GitHub Desktop.
using System;
using System.Windows.Forms;
public class Sample1:Form
{
private Label lb;
private TextBox tb;
public static void Main(){
Application.Run (new Sample1 ());
}
public Sample1(){
this.Text ="Sample";
this.Width = 200;
this.Height = 200;
lb = new Label ();
lb.Text = "Welcome";
lb.Dock = DockStyle.Top;
tb = new TextBox ();
tb.Dock = DockStyle.Bottom;
lb.Parent = this;
tb.Parent = this;
tb.KeyDown += new KeyEventHandler (tb_KeyDown);
}
//sender:送り主の情報(この場合tb)
//KeyEventArgs:イベントそのものに関連する情報(この場合KeyDown)
//つまり送り主自体の情報(sender)とイベントの情報(e)がある。
public void tb_KeyDown(Object sender, KeyEventArgs e){
//senderはObject型なのでらTextBox型いCastで取り出しているよ
TextBox tmp = (TextBox)sender;
//イベント情報のeを使っている
if (e.KeyCode == Keys.Enter) {
lb.Text = tmp.Text+" is selected";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment