Skip to content

Instantly share code, notes, and snippets.

@kazuooooo
Created December 30, 2014 10:23
Show Gist options
  • Save kazuooooo/38d23d04f9067499e33e to your computer and use it in GitHub Desktop.
Save kazuooooo/38d23d04f9067499e33e 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);
}
public void tb_KeyDown(Object sender, KeyEventArgs e){
//senderにはObjectとして色々情報が入っている。
//その中からTextBoxの情報をCastで取り出しているよ
TextBox tmp = (TextBox)sender;
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